cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Friendly URLs problem

Custom Friendly URLs problem

Hello

 

I am trying to create a mod_rewrite rule that will handle transparently rewriting a friendly URL to a query string redirect behind the browser.

 

Every  tutorial says to use the 'last' flag [L]

but this does not work, per se. or it seems not to.


The original URL that works looks like this

http://<domain>/locations?state=123&city=343 

 

my friendly URL looks like this 

http://<domain>/locations/123/343

 

my rewrite rule looks like this

RewriteCond %{THE_REQUEST} ^GET\ /locations/
RewriteRule ^locations/(.*)/(.*)$ /locations?state=$1&city=$2 [L]


I get a 404 error when I try to his my friendly URL

however, if I add the 'redirect' flag [R]

RewriteCond %{THE_REQUEST} ^GET\ /locations/
RewriteRule ^locations/(.*)/(.*)$ /locations?state=$1&city=$2 [R, L]


The URL redirects  and  the page loads, however the address bart gets updated to read 

http://<domain>/locations?state=123&city=343


Why does the redirect work but the non-redirect not?
is it because it's too late for Apache to consume the rewritten URL and re-parse it to the actual final URL?

How might I get around this?