Help with mod rewrite rules

Hello forums,

Please help me with this mod rewrite rule:

RewriteRule ^hitch/([A-Za-z0-9-]+).html/?$ hitch.php?action=make&year=$1 [NC,L]

applies for:

However my client wants the format to be I tried:

RewriteRule ^hitch-([A-Za-z0-9-]+).html/?$ hitch.php?action=make&year=$1 [NC,L]

But it doesn’t work

Any ideas?



Please use the [noparse]


[/noparse] wrapper for your code.

RewriteRule ^hitch/([COLOR="#FFA07A"][A-Za-z0-9-]+[/COLOR]).html[COLOR="#FF0000"]/?[/COLOR]$ hitch.php?action=make&year=$1 [[COLOR="#FF0000"]NC[/COLOR],L]

That will give you problems because the /? in the regex will be interpreted as one of two subdirectory levels which will ruin your relative links (css, js, gif, jpg, etc). Then, what year has a letter in it? Why not (/d{4}) for the atom? That will match a four digit year value. If you’re looking at 2000 - 2050, (20[0-5][0-9]). Specificity counts! Then, what the heck are you thinking about asking for No Case in a URI? That will not work for {REQUEST_URI}s because they ARE case specific! IMHO, don’t use the NC flag except on {HTTP_HOST} unless you have a very good reason.

To appease your client, use:

RewriteRule ^hitch-(20[0-5][0-9])\\.html$ hitch.php?action=make&year=$1 [L]

Lastly, you could use a tutorial like the one linked in my signature (with sample code).



Thanks DK that works (as usual)
“(20[0-5][0-9])” is cool but I have strings like 1990-to-2001 so I’m keeping “([A-Za-z0-9-]+)”.
Honestly I have no idea what NC means lol … tnx for the info

You Rock !


OIC. :tup: