apache重写某些网址是http而不是https

时间:2016-11-23 12:58:35

标签: apache .htaccess mod-rewrite

除了早先的问题,我还需要重写网址,例如

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

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

我用它来修复它

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

我还发现我也有与https相同的网址

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

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

正在给我重复的页面处罚

是否可以修改我的重写规则,以便在删除

的同时重定向到http页面
&main_page=products_categories 

后缀以便

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

会变成

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

1 个答案:

答案 0 :(得分:1)

不确定为什么这个问题不公平地被投票。

您可以使用此单一规则将这两个网址重定向到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]
相关问题