我正在尝试使用以下规则创建.htaccess文件:
http://www.example.com/test => https://example.com/test
http://test.example.com/test => https://test.example.com/test
https://www.example.com/test => https://example.com/test
这是我当前的.htaccess文件:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
这会引起一些奇怪的行为:
http://www.nebla.co.uk/ => https://nebla.co.uk/public_html
它还会在子域上引起重定向循环。
答案 0 :(得分:0)
我设法通过而不是使用
来修复我的行为RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
我将$ 1更改为%{REQUEST_URI}
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]