简体   繁体   English

简化到非www SSL的重定向域

[英]Simplify redirect domain to non-www SSL

I am using the follow .htaccess code to do the following: 我正在使用以下.htaccess代码执行以下操作:

.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM