Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
htaccess,在站点根目录中添加index.php_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

htaccess,在站点根目录中添加index.php

htaccess,在站点根目录中添加index.php,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,这是我当前的访问权限: 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|google1

这是我当前的访问权限:

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不存在,则添加www

最终目标是拥有如下URL:

ou

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

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]

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

谢谢您的帮助。我测试了你的建议,apache返回500。有点不对劲:/啊!我打错了。现在修好了。你能再试一次吗?太好了!你是个天才:)