[英].htaccess SSL redirect with url rewrite
我需要你的帮助。 假设这是我的网站:example.com
我想将http重定向到https。 此外,我还要重写网址。 如果我通过以下方式访问网站:
https://example.com/new
一切正常。
如果我使用http://www.example.com/new
访问该网站,它将重定向到https,但不会重写该URL。 结果是这样的:
`https://example.com/old`
RewriteEngine on
RewriteRule ^new/(.*)$ old/$1 [L,QSA]
RewriteCond %{HTTPS} =off [NC,OR]
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]
我试图将规则放在另一个顺序中,但这根本没有用。
我希望你能帮助我。 非常感谢:)
如果您只想删除www
,则只需要这样做。
RewriteEngine on
RewriteCond %{HTTPS} ^off [OR]
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]
RewriteRule ^new/(.*)$ old/$1 [L,QSA]
规则
RewriteRule ^new/(.*)$ old/$1 [L,QSA]
被配置为L
(最后),因此一旦匹配就不再处理其他规则。
您需要切换规则的顺序。 在提到的规则之前添加HTTPS重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.