繁体   English   中英

htaccess,方法是在网站根目录中添加index.php

[英]htaccess by adding index.php in the root of the site

这是我当前的htaccess:

RewriteEngine on

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_URI} !^/1EE772B8EBDDECBA378B575830E7E1B3\.txt$
RewriteCond $1 !^(index\.php|assets|wmt|google1f91ad48697ced36\.html|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{HTTP_HOST} ^domain.com.br$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
Options -Indexes

在第一行中,它将http重定向到https; 在第二个块中,它允许直接访问并删除index.php

如果它不存在,则在第三块中添加www。

最终目标是拥有如下网址:

https://www.domain.com.brhttps://www.domain.com.br/foo/bar

问题是,当用户输入地址Domain.com.br(不带www且不带http,仅在网站的根目录中)时,它重定向到:

https://www.domain.com.br/ index.php

仅在网站的根部添加此index.php

有谁知道我要去哪里错了?

我也接受htaccess优化建议

您可以使用以下重构规则:

Options -Indexes
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_URI} !^/1EE772B8EBDDECBA378B575830E7E1B3\.txt$
RewriteCond $0 !^(index\.php|assets|wmt|google1f91ad48697ced36\.html|robots\.txt) [NC]
RewriteRule .* index.php/$0 [L]

完全清除浏览器缓存后,对其进行测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM