[英]Simplify redirect domain to non-www SSL
I am using the follow .htaccess code to do the following: 我正在使用以下.htaccess代码执行以下操作:
/$1
to index.php?get=$1
将/$1
之后的所有内容重写为index.php?get=$1
.htaccess 的.htaccess
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^([^.]+)/?$ index.php?get=$1 [L]
This works fine but can this code still be simplified? 这可以正常工作,但仍可以简化此代码吗?
You can combine http->https
rule and www
removal rule into a single rule and have your .htaccess as this: 您可以将http->https
规则和www
删除规则合并为一个规则,并使用.htaccess进行如下操作:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ index.php?get=$0 [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.