2015-12-24 34 views
1

我有網址與編碼斜槓(%2F),我不能讓重寫規則正確地抓住這個。htaccess的HOWTO改寫編碼的斜槓的URL

我的網址是:

http://example.com/some-path/description%2Frest-of-description/1101 

我已經試過像重寫: -

# is the %2F interpreted as a path separator 
RewriteRule ^some-path/(.*)/(.*)/(.*)$ /property/view?ref=$3 [B,R=301,L] 
# or is it as an encoded string 
RewriteRule ^some-path/(.*)%2F(.*)/(.*)$ /property/view?ref=$3 [B,R=301,L] 
# or even double encoded 
RewriteRule ^some-path/(.*)%252F(.*)/(.*)$ /villas/$1-$2/$3 [B,R=301,NE,L] 

我也嘗試添加QSA以上。

關於被如此here過類似的問題,但它是IIS和基於.NET

我運行LAMP堆棧

+2

選中此:http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes – Nikhil

+0

@Nikhil你應該添加作爲一個答案(多一點信息)。 – MrWhite

+0

我嘗試添加AllowEncodedSlashes開,虛擬主機和所有請求獲得500 ...阿帕奇2.4 – ChrisB

回答

3

出於安全原因拒絕阿帕奇%2F。見urlencoded Forward slash is breaking URL

您可以關閉這個在您的服務器配置AllowEncodedSlashes指令。

但是,如果你編碼的網址,如果你有這部分代碼的控制會更好。

+0

thx,但不能得到它的工作。如果放置在httpd.conf或虛擬主機中,則提供500。也許一個OSX錯誤(我的開發機器)...稍後會嘗試在Linux機器上。 – ChrisB

+0

看,如果這個職位帶來一些幫助:http://stackoverflow.com/questions/4390436/need-to-allow-encoded-slashes-on-apache – NBK

+0

是的,這是得到了它 - THX!只是爲了記錄,我不能以不同的方式對url進行編碼,因爲它們已經在google索引中。事實上,在試圖重新映射它們時,我遇到了這個錯誤。 – ChrisB