2012-02-15 113 views
1
URL



我的URL結構是這樣%2520(雙空間)的URL與空間

http://www.example.com/folder/index.php?dir=dir1 

爲了能夠從

http://www.example.com/folder/dir1 

訪問,並在同一時間重定向第一個URL到第二個,我的htaccess(在'文件夾'中)是

Options +FollowSymLinks 

RewriteEngine On 
RewriteBase /folder 

RewriteCond %{ENV:REDIRECT_STATUS} 200 
RewriteRule .* - [L] 

RewriteCond %{QUERY_STRING} ^dir=(.*)$ [NC] 
RewriteRule^%1? [L,R=301] 

RewriteRule ^(.+)/? index.php?dir=$1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} -d 

RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA] 

問題是如果URL中的任何目錄名稱包含「空格」,則該URL將顯示%2520而不是「空格」。

請在修改htaccess的建議,所以它顯示%20或最好是一個簡單的'空間'?

回答

2

試穿重定向,即增加一個NE

RewriteRule^%1? [L,R=301,NE] 

編輯

既然你讀過我的htaccess的,你看到了進一步縮短它

的任何方法可行

以下是幾條評論

Options +FollowSymLinks 

RewriteEngine On 
RewriteBase /folder 

RewriteCond %{ENV:REDIRECT_STATUS} 200 
RewriteRule .* - [L] 

RewriteCond %{QUERY_STRING} ^dir=(.*)$ [NC] 
RewriteRule^%1? [L,R=301] 

#this looks redundant with last rule, and could be deleted? 
RewriteRule ^(.+)/? index.php?dir=$1 [L,QSA] 

#this says if not an existing file 
RewriteCond %{REQUEST_FILENAME} !-f 
#and this says if it IS an existing directory 
#Is this what you wanted, or should it be not an existing directory i.e 
# RewriteCond %{REQUEST_FILENAME} !-d instead 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA] 
+0

它的工作原理!非常感謝..既然你已經閱讀過我的htaccess,你是否看到有進一步縮短它的可能性? – Umer 2012-02-15 02:56:12

+0

@ user1170540查看更新 – 2012-02-15 03:09:48