通过在站点的根部添加index.php来htaccess



这是我当前的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。

最终目标是拥有:

之类的URL

https://www.domain.com.br ouhttps://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]

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

最新更新