我的要求非常简单,我想要一套可以做以下事情的RewriteRule
最终我的网址要求就像http://domain.com
我可以做大多数事情,但像https://www.domain.com这样的请求不会重定向。
这是我的重定向规则:
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*) http://domain.com/$1 [L,R=301]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
请建议我需要做什么。
答案 0 :(得分:0)
使用以下代码
RewriteEngine On
#Redirect HTTP with www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS with www to HTTPS without www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]