Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex for URL routing - match alphanumeric and dashes except words in this list
    primarykey
    data
    text
    <p>I'm using CodeIgniter to write an app where a user will be allowed to register an account and is assigned a URL (URL slug) of their choosing (ex. domain.com/user-name). CodeIgniter has a URL routing feature that allows the utilization of regular expressions (<a href="http://ellislab.com/codeigniter/user-guide/general/routing.html" rel="nofollow">link</a>).</p> <p>User's are only allowed to register URL's that contain alphanumeric characters, dashes (-), and under scores (_). This is the regex I'm using to verify the validity of the URL slug: <code>^[A-Za-z0-9][A-Za-z0-9_-]{2,254}$</code></p> <p>I am using the url routing feature to route a few url's to features on my site (ex. <code>/home -&gt; /pages/index</code>, <code>/activity -&gt; /user/activity</code>) so those particular URL's obviously cannot be registered by a user. </p> <p>I'm largely inexperienced with regular expressions but have attempted to write an expression that would match any URL slugs with alphanumerics/dash/underscore except if they are any of the following: </p> <ol> <li>default_controller</li> <li>404_override</li> <li>home</li> <li>activity</li> </ol> <p>Here is the code I'm using to try to match the words with that specific criteria: </p> <pre><code>$route['(?!default_controller|404_override|home|activity)[A-Za-z0-9][A-Za-z0-9_-]{2,254}'] = 'view/slug/$1'; </code></pre> <p>but it isn't routing properly. Can someone help? (side question: is it necessary to have <code>^</code> or <code>$</code> in the regex when trying to match with URL's?)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload