我正在使用以下.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]
这样可以正常工作,但这段代码仍然可以简化吗?
答案 0 :(得分:0)
您可以将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]