2010-02-08 91 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