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?

link|improve this question
Try putting a backslash in front of the colon. – Chris S May 9 '11 at 18:16
What happens if you set it to rewrite $(.*)^ to, say, index.php?q=$1 and have index.php <?php echo $_GET['q']; ?> ? (Your rule as it is seems to work for me on Ubuntu Maverick, albeit in a .htaccess file) – PeterJCLaw May 9 '11 at 18:31
@PeterJCLaw That RewriteRule also results in a 403 forbidden error if I pass any parameters with a colon. – Adam Prax May 9 '11 at 19:12
That's odd. I'm wondering if you've got something in your apache config that's specifically blocking urls containing colon generally. Is anything useful appearing in the access.log or error.log files? – PeterJCLaw Aug 28 '11 at 15:25
show 1 more comment
feedback

1 Answer

When in doubt.. Always escape

RewriteRule ^hello\:world$ /hello/world.html [L,QSA]
link|improve this answer
I've tried escaping the colon, but still got the 403 Forbidden error – Adam Prax May 9 '11 at 18:20
1  
I would expect that Apache expects it to be properly escaped as %3A. – DerfK May 9 '11 at 18:32
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.