Apache Rewrite Rule not Matching Colon (:)

apache-2.2mod-rewrite

I'm having trouble writing a rule that will rewrite an address like http://localhost/hello:world to http://localhost/hello/world.html

My RewriteRule in httpd.conf is as follows:

<Directory "D:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
     Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all

     RewriteEngine On
     RewriteBase /
     RewriteRule ^hello:world$ /hello/world.html [L,QSA] #Doesn't work
     RewriteRule ^hello_world$ /hello/world.html [L,QSA] #Works great!
 </Directory>

When I try http://localhost/hello:world, I receive a 403 Forbidden page.

Of particular note, the rule

RewriteRule ^hello_world$ /hello/world.html [L,QSA]

works just fine with http://localhost/hello_world.

I am using Apache2.2 under Windows Server 2008.

How would I rewrite the rule to match the colon?

Best Answer

When in doubt.. Always escape

RewriteRule ^hello\:world$ /hello/world.html [L,QSA]
Related Topic