我是操纵.htaccess
的新手,我正在尝试使用.htaccess
在网页上强制使用https,因此,如果用户尝试访问http//localhost/myproject/
,则会重定向到{{ 1}}如下:
https//localhost/myproject/
问题在于,在加载RewriteEngine on RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
AddDefaultCharset UTF-8
时,浏览器不会重定向到http//localhost/myproject/
,而是将其返回:
https//localhost/myproject/
如果我删除此行Found
The document has moved here.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
,浏览器会加载uri RewriteRule ^(.*)$ index.php/$1 [L,QSA]
,但https//localhost/myproject/
之类的其他每条路径都不会加载投掷错误404.
.htaccess有什么问题?怎么可以解决?
答案 0 :(得分:2)
您需要将[L,R=301]
添加到规则中,以便进行重定向,然后下一个规则将在下次加载时运行。
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]