Steve Price Steve Price - 15 days ago 5
Apache Configuration Question

apache rewrite for certain urls to be http instead of https

Further to an earlier question I had where I needed to rewrite urls such as

http://example.com/index.php?cPath=371_1659_1660&main_page=products_categories


to

http://example.com/index.php?cPath=371_1659_1660


I used this to fix it

RewriteCond %{QUERY_STRING} ^(.)(^|&)main_page=products_categories(.)$
RewriteRule ^(.*)$ /$1?%1%3 [R=301,L]


I've also discovered that I also have the same urls as https so

https://example.com/index.php?cPath=371_1659_1660&main_page=products_categories


and

http://example.com/index.php?cPath=371_1659_1660&main_page=products_categories


are giving me duplicate page penalties

Is it possible to modify my rewrite rule so that it also redirects to the http page at the same time as removing the

&main_page=products_categories


suffix so that

https://example.com/index.php?cPath=371_1659_1660&main_page=products_categories


would become

http://example.com/index.php?cPath=371_1659_1660

Answer

Not sure why this question was unfairly down voted.

You can use this single rule to redirect both URLs to http://...:

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)main_page=products_categories(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)(cPath=[^&]+) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}?%1 [R=301,L,NE]