Multiple RewriteCond .htaccess Query String Redirects

Posted by Damodar Bashyal on May 29, 2014

 

It's easy to redirect simple page urls from one location to another but query strings redirection can make you pull your hair.

This is how I redirected simple pages:

Redirect /page.php http://technooze.com/new-page

For mass redirecting of pages after folder path:

RedirectMatch ^/cms/(.*).php$ http://technooze.com/blog/$1

For query string 301 redirect.

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page/$
RewriteCond %{QUERY_STRING} ^id=about$
RewriteRule ^(.*)$ http://technooze.com/about-us? [R=301,L]

RewriteCond %{REQUEST_URI}  ^/page/$
RewriteCond %{QUERY_STRING} ^type=product&id=1$
RewriteRule ^(.*)$ http://technooze.com/shop/caps? [R=301,L]

I created new page that would get product id and redirect to proper product page, so updated above code to:

RewriteCond %{REQUEST_URI}  ^/page/$
RewriteCond %{QUERY_STRING} ^type=product&id=([0-9]*)$
RewriteRule ^(.*)$ http://technooze.com/shop/load=%1? [R=301,L]

And I redirected all other remaining pages to base url by adding below line after above conditions.

RewriteRule ^(.*)$ http://technooze.com/ [R=301,L]

 

 
not published on website


QR Code: Multiple RewriteCond .htaccess Query String Redirects