回退资源指令给出 500 内部服务器错误



我正在使用WAMP。我有一个目录结构如下的项目:

my_project/
    -folder_1
    -folder_2
    -404.php
    -.htaccess
    -router.php
    -index.php
    -file_1.php
    -file_2.php

现在的计划是将所有不匹配的页面请求重定向到"router.php"。从这个router.php我想将请求重定向到适当的 php 页面。

为了将所有不匹配的传入请求定向到router.php,我在.htaccess文件中编写了以下行。但是,当我单击无效/不匹配的超链接时,它不会将我带到router.php页面,而是显示"500 内部服务器错误"。

FallbackResource router.php

请告知我的代码有什么问题。

可能是因为它找不到router.php,因此陷入了递归。如果您检查错误日志,您可能会发现类似以下内容的内容:

Request exceeded the limit of 10 subrequest nesting levels due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

试试这个:

FallbackResource /router.php #Note the leading slash.

如果my_project/目录不是您的文档根目录,并且您必须像localhost/my_project一样访问它,您还需要提及目录层次结构:

FallbackResource /my_project/router.php

所以,如果它是 localhost/foo/bar/my_project ,它将是:

FallbackResource /foo/bar/my_project/router.php

最新更新