Link to home
Start Free TrialLog in
Avatar of jhmplondon
jhmplondon

asked on

Replacing spaces in URL (%20) with mod_rewrite

Hi guys,

I'm trying to rewrite URLs I have at the moment (it's dynamic website, so I can't change the html itself). Some of them have spaces, so users see %20 in the middle of string, it looks pretty messy.

Here are examples of URLs I'm trying to rewrite

http://www.mydomain.com/New%20York.html

http://www.mydomain.com/dancer/New%20York

I tried this:
Options +SymlinksIfOwnerMatch
RewriteEngine on

RewriteCond %{REQUEST_URI} ^(.*)\ (.*)$
RewriteRule ^.*$ %1_%2 [E=space_replacer:%1_%2]
RewriteCond %{ENV:space_replacer} !^$
RewriteCond %{ENV:space_replacer} !^.*\ .*$
RewriteRule ^.*$ %{ENV:space_replacer} [R=301,L]

Open in new window


but didn't work.

Thanks for help
Tom
ASKER CERTIFIED SOLUTION
Avatar of TonyReba
TonyReba
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial