user1170540
user1170540

Reputation:

%2520 (Double space) in URL for URL with spaces



My URL structure is like

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

To be able to access it from

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

and at the same time redirect the 1st URL to 2nd one, my htaccess (in 'folder') is

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]

The trouble is that if any directory name in URL contains a 'space', the URL shows %2520 instead of the 'space'.

Please advice in modifying the htaccess so it shows %20 or preferrably a simple 'space'?

Upvotes: 1

Views: 2635

Answers (1)

Ulrich Palha
Ulrich Palha

Reputation: 9519

try adding a NE on the redirect ie

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

EDIT

Since you've read my htaccess, do you see any possiblity of shortening it further

Below are a couple of comments

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]

Upvotes: 2

Related Questions