2012-11-08 51 views
0

我想重寫一個簡單的URL,但不會產生谷歌的錯誤重寫規則錯誤

此代碼:

RewriteEngine on 
RewriteRule lieu/([0-9]+).* index.php?com=location&lID=$1 [L] 
RewriteRule evenement/([0-9]+).* index.php?eID=$1 [L] 

,但我想加上R = 301標誌SEO

當我添加[R = 301,L]:

The requested URL /var/www/mysite/index.php was not found on this server. 

我知道R = 301標誌必須以http使用://

但是當我嘗試的網址並非rewritting

+0

當然這個目標URL不是有效的URL。這是一個服務器路徑(目錄路徑)。 – Madbreaks

+0

@Madbreaks確定,但你有什麼建議? – bklups

+0

請向我們展示您的完整重寫塊,其中包括301 – Madbreaks

回答

0

阿帕奇試圖猜測一個路徑是URI路徑或文件路徑,它猜錯。當你在內部重寫時,文件路徑非常好,因爲它全部在服務器內部。但是當你重定向時,apache錯誤地猜測你的目標(index.php?eID=)是一個文件路徑,它被標記爲由mod_alias作爲重定向處理。到重定向發生時,它的格式變爲文件路徑而不是URI路徑。這就是爲什麼當你重定向時你得到了/var/www/mysite/位。

要麼添加RewriteBase爲相對URI提供一個URI的基礎,或者使你的目標絕對URI:

RewriteEngine On 
RewriteBase/
RewriteRule lieu/([0-9]+).* index.php?com=location&lID=$1 [R=301,L] 
RewriteRule evenement/([0-9]+).* index.php?eID=$1 [L,R=301] 

RewriteEngine on 
RewriteRule lieu/([0-9]+).* /index.php?com=location&lID=$1 [L,R=301] 
RewriteRule evenement/([0-9]+).* /index.php?eID=$1 [L,R=301] 
+0

我沒有這個錯誤/ var/www/mysite /),但只要添加R = 301標誌,URL不會更改。它只與唯一的L標誌 – bklups

+0

鏈接是好的,但沒有出現在瀏覽器的地址欄 – bklups

+0

@bklups我忘了添加'R = 301'標誌到第一條規則 –