2013-04-03 70 views
0

我試圖用我的網站中的破折號替換所有的下劃線。我面臨一些問題。htaccess不會在完整的url中替換下劃線

問題1

下面

是在我的網站的網址

http://localhost/uk_london when clicked redirects to http://localhost/uk-london 

,但下面的URL添加在URL的末尾附加破折號,並返回404錯誤

http://localhost/united_states http://localhost/united-states- (gives 404) 

當我在最後刪除短劃線它正常工作。

問題2

儀表板被更換時,纔會有只有一個URL段。在下面的網址中,沒有下劃線被替換爲破折號。下面

http://localhost/london_uk/city/products_availability_london 

是我的htaccess代碼

RewriteEngine On 
RewriteBase/

RewriteRule ^assets - [L,NC] 

RewriteRule !\.(html|php)$ - [S=4] 
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes] 
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes] 
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes] 
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes] 

RewriteCond %{ENV:uscor} ^Yes$ 

進出口新的htaccess的,想知道是什麼原因導致了這些問題。 任何解決問題的幫助將不勝感激

回答

0

嘗試更換:

RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes] 
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes] 
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes] 
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes] 

只需:

RewriteRule ^(.*)_(.*)$ /$1-$2 [L,E=uscor:Yes] 

重寫引擎將循環並刪除所有下劃線的,只要你沒有比內部重定向限制更多的下劃線(將導致500錯誤)。

+0

@ Joni-Lin當我替換該代碼時,沒有任何下劃線被替換?它只是作爲通常的網站...任何想法爲什麼? –