【发布时间】:2016-02-18 00:21:13
【问题描述】:
我正在尝试在我的.htaccess 中设置一些规则,以便以特定方式工作:
-
特定页面重定向:
RewriteRule "^web/site/mais$" https://www.main.com/front/for-you/insurance/ [R=301,L] -
首页重定向
RewriteRule ^$ https://www.forexample.com.br/for-you/ [R=301,L] RewriteRule ^/$ https://www.forexample.com.br/for-you/ [R=301,L] -
HTTP 到 HTTPS 并将 www 添加到其余部分(这是行不通的),我尝试了很多东西:
RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTPS} !^on$ [OR] RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} ^www\. RewriteCond %{HTTPS} !^on$ [OR] RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
我尝试忘记 www 规则的其他方式(但也不起作用):
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
我发现合并的唯一方法是将一般的https 和www 规则写入httpd.conf 并将其他规则写入.htaccess,但是这样我得到两个或更多的301 重定向,生意不好搜索引擎优化。
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite