我使用下面的.htaccess代码执行以下操作:
/$1之后的任何内容重写为index.php?get=$1.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]这很好,但是这段代码还能简化吗?
发布于 2017-06-02 16:34:34
可以将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]https://stackoverflow.com/questions/44330473
复制相似问题