2

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 bar 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?

  • 4
    I'm voting to close this question as off-topic because this is an HTACCESS question – brentwpeterson Jul 18 '16 at 17:42
  • Welcome to Magento SE. This does not look like a Magento related question, because Magento works with "friendly" URLs instead of ?state=x&city=y out of the box, so there are no additional mod_rewrite rules required. If it actually is about Magento, please try to explain what you are trying to achieve to get an answer how to solve it in code. See: meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Fabian Schmengler Jul 18 '16 at 20:53
  • (otherwise try your luck at serverfault.com instead) – Fabian Schmengler Jul 18 '16 at 20:54