Forum Moderators: phranque

Message Too Old, No Replies

String matches in PHP, but not in .htaccess

         

majstro

11:10 am on Aug 31, 2011 (gmt 0)

10+ Year Member



I have this rewrite rule in a .htaccess file:

RewriteRule ^Old.English-English$ /Web/Majstro/bdict.php?gebrTaal=eng&bronTaal=ang&doelTaal=eng&index=Y [NC,L]

For some reason the regular expression in the file does not match the string "Old English-English", although it does match when tested in PHP.

However, if I change the regular expression to ^Old.Englisi-English$, it will match to "Old Englisi-English", and the same happens when the "h" of "Old English" is replaced by any other letter.

Similar rewrite rules with regular expressions like ^West.Frisian-English$ have never caused problems, so why does this one not work?

majstro

1:32 pm on Aug 31, 2011 (gmt 0)

10+ Year Member



I've done some more experimenting. If I change the regex to ^Old.English.*$ any URL starting with "Old English" is rewritten (as expected), EXCEPT when "Old English" is followed by "-English". For instance, "-english" and "_English" work fine, but for some reason a hyphen with identical substrings on its left and right side, causes a problem.

g1smd

1:37 pm on Aug 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If that's a literal period in that pattern then escape it.

Use the Live HTTP Headers extension for Firefox to see what is going on.

majstro

2:35 pm on Aug 31, 2011 (gmt 0)

10+ Year Member



Okay, using Live HTTP headers revealed that Firefox was messing up the URL, not Apache.

The same URL returns the correct page in IE and Chrome, so apparently it's a bug in Firefox.

lucy24

8:43 pm on Aug 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If that's a literal period in that pattern then escape it.

It isn't. This is the rare case where the best way to get around an ill-conceived url is to use the generic . "any character, in this case a literal space".

If IE and Chrome do it one way and Firefox does it another, I would be inclined to suspect that Firefox is doing what it's supposed to do, while the first two aren't. What happens in Opera? Does Safari behave the same as Chrome?

In any case, I strongly advise getting rid of any spaces in urls. :: insert asking-for-trouble boilerplate :: I mean really getting rid of them, not just rewriting.