Forum Moderators: phranque
RewriteRule ^([A-Za-z0-9-]+)$ /cms/$1.php [L]
... the .htaccess file is fine, but when I add an underscore between the square brackets:
RewriteRule ^([A-Za-z0-9-_]+)$ /cms/$1.php [L]
... I receive an Internal Server Error.
This only happens on one particular server (I think). Should this not work either way?
Patrick
A-Z is interpreted as "any uppercase character from A to Z," then "a-z" is interpreted as "any lowercase character from a to z," then "0-9" as "any numeric character," and then the parser hits "_-]" and tries to interpret that as "any character, from underscore to right square bracket" which of course is invalid (because right square bracket is a lower character-code value than underscore).
And even if that did work, then the character-group would be left unclosed since the right square bracket has already been parsed and "consumed."
I recommend escaping the hyphen when not intended as a "range indicator" -- That is, use "\-" to avoid all ambiguity.
Also, see the mod_rewrite [NC] flag, which makes character-matching case-insensitive. In many cases, it can be used to shorten [A-Za-z] to just [A-Z] or [a-z], and eliminates an entire range-comparison step.
Jim
RewriteRule ^([A-Za-z0-9_-]+)$ /cms/$1.php [L]
... didn't cause an error. The error was caused by the underscore after the hyphen:
RewriteRule ^([A-Za-z0-9-_]+)$ /cms/$1.php [L]
Point taken re the [NC] flag.
Patrick