2010-02-08 54 views
0

我使用mod_rewrite来创建SEO网址。基本上这个工作的方式如下: 所有请求都被.htaccess捕获并重定向到一个php脚本(比如说transform.php)。 transform.php解析SEO URL并将其转换为普通URL,然后包含index.php,然后捕获应用程序的(index.php)输出并使用RegEx将所有普通URL转换为SEO URL。 因此,重要的一步是使所有请求都通过transform.php。我的.htaccess是相当长,但我设法限制它到以下几行。.htaccess mod_rewrite在不同的网站上有不同的结果

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    RewriteEngine on 

    RewriteRule ^index\.php?(.*)$ ./transform.php?p=$1&%{QUERY_STRING} [L] 

</IfModule> 

问题发生在初始(根)URL:http://mysite.com/。当我输入http://mysite.com/和网站位于我的本地比较,一切工作正常。 http://mysite.com/被.htaccess捕获并发送到transform.php以供进一步处理。但是在另一台服务器上,这条线路不起作用(比如说http://mysite-other-server.com/)。这个.htaccess行根本没有收到请求。虽然一切工作正常http://mysite-other-server.com/index.php

而且我有这样的第二台服务器上的几个地点,其中一些工作,而他们中的一些没有。这就像其中一些URL首先解析为http://mysite-other-server.com/index.php,然后由.htaccess处理,而其他人的URL不解决和.htaccess处理http://mysite-other-server.com/

我很困惑,并尝试Google没有任何运气。任何帮助,高度赞赏。

回答

1

我认为Apache的配置不接受.htacces文件。

必须从具有的AllowOverride设置的httpd配置启用它。

http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride

另一种可能是生产服务器尚未加载了mod_rewrite,检查了的LoadModule指令。

+0

嗨,谢谢你的回复! 服务器肯定接受.htaccess文件,因为http://mysite-other-server.com/index.php按预期工作。 mod_rewrite也是一样。但由于某种原因http://mysite-other-server.com/不会产生相同的结果。它仍然进入.htaccess文件,但是 RewriteRule^index \ .php?(。*)$ .... 没有任何影响。 ?(*),而在这同一服务器 重写规则^指数\ $ .PHP在其他网站上....工作正常http://mysite-other-server.com/ – Eugene 2010-02-08 20:05:11

+0

所以要理清头绪: HTTP: //mysite-other-server.com/ 和 http://mysite-other-server123.com/ 在同一台服务器上。 两者都使用相同的.htaccess文件和transform.php。 http://mysite-other-server123.com/和http://mysite-other-server123.com/index.php都与该正则表达式匹配并进入transform.php 但只有http:// mysite-other -server.com/index.php匹配,而http://mysite-other-server.com/不匹配。 – Eugene 2010-02-08 20:05:48

+0

请注意,AllowOverride指令可以设置为特定的VirtualHost,从而允许一个Apache有一个域可以工作,另一个不可以。 – Johnco 2010-02-08 20:08:57