%2520(双空间)的URL与空间

问题描述:

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或最好是一个简单的'空间'?

试穿重定向,即增加一个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