Vyshnavi Samudrala Vyshnavi Samudrala - 2 months ago 25
Apache Configuration Question

Redirect URLs with parameters

I have URLs like

www.mysite.com/city/some-url-structure


I need to add parameters to the end of the URL like

www.mysite.com/city/some-url-structure?sort_value=distance


How do I make a rewrite rule in
.htaccess
file to get that?

Answer

You can use this redirect rule:

RewriteEngine On

RewriteCond %{QUERY_STRING} !(^|&)sort_value=distance(&|$) [NC]
RewriteRule ^city/some-url-structure/?$ %{REQUEST_URI}?sort_value=distance [L,NC,QSA,NE,R=301]