Rewrite and redirect dynamic url with .htacces -
ok website has dynamic url
web.com/?city=londonwant change
web.com/londonwhile found code rewrite i'm struggling find 1 changes , immediatly redirects people url in format.
well, this:
rewriteengine on rewritecond %{env:redirect_status} ^$ rewritecond %{query_string} (?:(.*)&)city=([^&]+)(.*) rewriterule ^(index.php)?$ %2?%1%3 [r,l] rewritecond %{env:redirect_status} ^$ rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewritecond %{request_uri} !\.(js|css|jpe?g?|png|gif)$ rewritecond %{request_uri} !^index.php rewriterule ([^/]+) index.php?city=$1 [l,qsa]
- the first part responsible rewriting original urls "pretty" format , redirect browser it
- note first part rewrites empty uri , "index.php" (assuming thats directory index file).
- the second part, rewrites request "back"
index.php?city=london
, , serves newly created request sub-request (hiding real url browser).
however, note results in unnecessary redirects of browser, instead of relying heavily on part 1 of scenario, should consider reconstructing urls within server-side application, appear in "correct" form begin with.
Comments
Post a Comment