Forum Moderators: phranque

Message Too Old, No Replies

trouble matching specific word with mod rewrite

general match works, specific match doesn't

         

HBird

7:26 pm on Feb 13, 2011 (gmt 0)

10+ Year Member



I am new to mod_rewrite and starting fairly simple. I have two URLs with the same format, but one looks for a specific first word while the other matches any word.

This rule works:

# Site ($country/$name) e.g. uk/westminster-abbey
RewriteRule ^([a-z\-]+)/([a-z\-]+)$ site.php?country=$1&name=$2 [L]

But this more specific one, with the same URL format, doesn't work (I get an Internal Server Error):

# Person (person/$name) e.g. person/winston-churchill
RewriteRule ^person/([a-z\-]+)$ person.php?name=$1 [L]

FYI, I comment out all rules except the one I'm testing, so interaction isn't the issue.

All I've done is change the first atom to match the specific word "person". Can anyone see what is wrong with it? I've looked at lots of examples online and it seems like it's the right regex format.

Maybe I should be using a conditional for this rule? But my understanding is that would be slower, and it seems the above rule should work.

This is driving me crazy! Thanks in advance for any help.

jdMorgan

9:56 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, this would drive me crazy as well -- nothing obviously wrong...

Does "person" contain any non-ASCII characters? (If in doubt about any other part of the line, just re-type the whole thing.)

What do you see in your server *error* log file when you get the 500-Server Error? (Correlate the error log entries with those in your server access log file by time while testing)

Jim

HBird

2:58 am on Feb 20, 2011 (gmt 0)

10+ Year Member



Thanks for the reply, Jim. It's very helpful to know you don't see any problems with the structure. It's bad news, though - I wish there was an error so I know what to fix!

I've looked at the error log and haven't been able to see my 500 errors in there yet for some reason. I'll keep looking and testing.

If anyone else has any suggestions, I would be very happy to hear them.

Thanks.

HBird

3:47 am on Feb 20, 2011 (gmt 0)

10+ Year Member



Update - it's working now! And I don't totally know why! I didn't change the rule, but I did remove a rule I had above it and hadn't noticed - it changed 'example' into 'example.php'. I have that in all my .htaccess files as default, but I realized I didn't need it here since I'm redirecting all URLs to look nice. So I deleted it. Then I messed about with a few other rules, and a few steps later, the problem code was working! Hooray! I guess it must have been the .php redirect interacting with it and causing an error. Thanks again for your help.