Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite and Apostrophes

         

trevordixon

9:40 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



My rewriterule looks like this:

RewriteRule ^appraisers/([A-Za-z_]+)/([A-Za-z_-]+)/?$ list_county.php?state=$1&county=$2 [L,QSA]

But I need to allow apostrophes in certain parts of the url. I tried both of the following rewriterules and both gave 500 Internal Server Errors:

RewriteRule ^appraisers/([A-Za-z_]+)/([A-Za-z_-']+)/?$ list_county.php?state=$1&county=$2 [L,QSA]

RewriteRule ^appraisers/([A-Za-z_]+)/([A-Za-z_-\']+)/?$ list_county.php?state=$1&county=$2 [L,QSA]

How do I make mod_rewrite allow apostrophes?

jdMorgan

10:13 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may have to handle them using RewriteCond, which operates on the unescaped URI. Check your links by hovering over one in your browser. You can probably detect them using

RewriteCond %{REQUEST_URI} \%27

as in:

RewriteCond %{REQUEST_URI} ^/appraisers/([a-z_]+)/(([a-z_\-]¦\%27)+)/?$ [NC]
RewriteRule ^appraisers/ list_county.php?state=%1&county=$2 [QSA,L]

Replace the broken pipe "¦" character above with a solid pipe before use; posting on this forum modifies that character.

Jim

trevordixon

6:35 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



The following is working for me. Is there anything wrong with this:

RewriteRule ^appraisers/([A-Za-z_]+)/(([A-Za-z_-]¦')+)/?$ list_county.php?state=$1&county=$2 [L,QSA]

jdMorgan

9:39 pm on Aug 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, that should work. But you could shorten/speed it up some using the [NC] flag as demonstrated above:

RewriteRule ^appraisers/([a-z_]+)/(([a-z_-]¦')+)/?$ list_county.php?state=$1&county=$2 [NC,QSA,L]

It's interesting that testing the ' within [] apparently does not work, but it does work if you use the local OR within parentheses. I've never run into that problem before.

For those reading later: Replace the broken pipe "¦" character above with a solid pipe before use; posting on this forum modifies that character.

Jim