【发布时间】:2021-01-10 13:16:06
【问题描述】:
真的很难理解htaccess的工作,我有这段代码:
#Remove slash on the end
RewriteRule ^(.*)/$ $1 [R=301]
#Don't use .php extension in URL
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php
#All the directories should be redirected to index.php
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . index [R=301]
我的根文件夹的结构:index.php、.htaccess 和 dir 目录,里面有 test.php 文件。
我知道这个文件会重新执行多次,直到 URL 的更改结束,所以如果我正在写 mysite.ru/index/dir/ 到地址栏(我使用现有的索引文件作为目录,否则,如果我使用单词与现有文件名无关,它可以工作),我期待 404 页面(斜杠删除,dir.php 不存在,索引/目录不存在,文件再次执行,URL 没有改变和它结束了),但我在 error.log 文件中收到 500 个错误和 10 个重定向。 .htacess 文件有问题,我无法理解。
【问题讨论】:
-
该请求最终调用 index.php 激活 RewriteLog