2014-08-31 53 views
0

我想重寫htaccess的重寫動態網址不工作

mypage.com/country/country.php?country=something 

mypage.com/country/something 
在地址欄中

,使用htaccess的

我試過很多東西,到處和我得到的最接近的是:

RewriteCond %{QUERY_STRING} country=([^\&]*) 
    RewriteRule ^country.php$ /country/%1? [R,L] 

但是,這只是產生一個重寫循環,在上面的兩個鏈接之間交替,我不明白爲什麼。

兩個我都想要

mypage.com/country.php?country=something 

mypage.com/country/something 

輸入的時候,展現

mypage.com/country/something 
在地址欄

任何幫助

回答

0

如果你有一個重寫循環,它表明除了這個規則之外,你還有一條規則將它翻譯回來。您需要「醜陋的」網址才能在外部請求時觸發。最簡單的方法是匹配%{THE_REQUEST}

#Ugly to fancy url; should be R=301 when it works 
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /country\.php\?country=([^\&]*)\ HTTP 
RewriteRule ^country.php$ /country/%2? [R,L] 

RewriteRule ^country/(.*)/?$ /country.php?country=$1 [L] 
+0

這是行得通!非常感謝你。你不知道這是多麼令人沮喪。我只需要使我的相對樣式錶鏈接和圖像完全相同,因爲重命名會改變它們的路徑並導致在沒有它們的情況下生成頁面。 – 2014-08-31 14:56:49

+0

使用''。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base – Sumurai8 2014-08-31 15:50:46