2012-04-02 50 views
1

我将我的网站从本地移动到服务器,我的.htaccess中的重写规则不起作用。无法打开需要'重定向:/index.php'(include_path ='。:/ usr/lib64/php:/ usr/lib/php')在Unknown 0行

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

这就是我在我的.htaccess中。

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

为了进一步诊断问题,我修改我的.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> 

现在,我得到一个奇怪的错误,而访问我site.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 
+1

该错误来自PHP。我不知道你的脚本是做什么的,但是检查文件权限(例如会话文件位置,编译模板/缓存文件等)。 **但通常情况下:**检查重写是否有效 - 进行临时重定向,以便网址也可以在浏览器中更改,例如'RewriteRule^contact-us $ index.php?p = 2 [R = 302,L]' – LazyOne 2012-04-02 14:56:29

+0

你可以直接打开http://你的主机名/ index.php?p = 2吗?它似乎汤姆我喜欢这个.htaccess文件所在的目录中没有index.php。 – 2012-04-02 20:00:23

回答

2

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

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

相关问题