无法打开必需的';重定向:/index.php';(include_path=';.:/usr/lib


Failed opening required 'redirect:/index.php' (include_path='.:/usr/lib64/php:/usr/lib/php') in Unknown on line 0

我将站点从本地移动到服务器,.htaccess中的重写规则不起作用。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^contact-us$ index.php?p=2
</IfModule>

这就是我的.htaccess.

但我确信.htaccess会被服务器识别(我通过在.htacccess中放入一些垃圾进行了测试——我得到了服务器错误)。

为了进一步诊断问题,我修改了我的.htaccess,如下所示:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^contact-us$ index.php?p=2
RewriteRule contact-us$ index.php?p=2
RewriteRule ^contact-us index.php?p=2
RewriteRule contact-us index.php?p=2
</IfModule>

现在,我在访问我的网站.com/contact-us 时遇到了一个奇怪的错误

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'redirect:/index.php' (include_path='.:/usr/lib64/php:/usr/lib/php') in Unknown on line 0

Apache以某种方式自动将.php添加到我的URL中。(我认为是因为AddHandler)

我有一个contact-us.php,但我想把contact-us路由到index.php?p=2。由于Apache正在添加.php并检查contact-us.php是否存在,因此它与contact-us路由不匹配。因此,我将文件重命名为php-contact-us.php,并保持路由和URL不变。因此,重定向现在按预期工作。