我正在尝试实现一个简单的http到https重定向和www到非www。问题是.htaccess将"index.php“置于url段塞之前,从而导致服务器错误。下面是发生的情况:
错误行为:
http://example.com/url-slug -> https://example.com/index.php/url-slug期望的行为:
http://example.com/url-slug -> https://example.com/url-slug注意:我希望所有查询都重定向到主目录中的index.php页面,除非请求的文件存在于服务器上。我希望在不更改浏览器中的url的情况下实现这一点,这会导致服务器崩溃。
(目标:www -> non& http -> https)
当前.HTACCESS设置:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]我做错了什么?
发布于 2020-01-14 04:54:53
您的http to https 301重定向应该在其他内部重写规则之前位于顶部。
RewriteEngine On
#http to https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule (.*) https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]在测试此更改之前,请确保清除浏览器缓存。
https://stackoverflow.com/questions/59722437
复制相似问题