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:
but didn't work.
Thanks for help
Tom
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]
but didn't work.
Thanks for help
Tom
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.