3

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?

Adam Prax
  • 131
  • 1
  • 3
  • Try putting a backslash in front of the colon. – Chris S May 09 '11 at 18:16
  • possible duplicate of [Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?](http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-ask) – Chris S May 09 '11 at 18:19
  • What happens if you set it to rewrite $(.*)^ to, say, index.php?q=$1 and have index.php ? (Your rule as it is seems to work for me on Ubuntu Maverick, albeit in a .htaccess file) – PeterJCLaw May 09 '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 09 '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
  • Hrm, after some googling it looks like this is a more general issue; colon is a reserved character (https://groups.google.com/forum/#!topic/apache2/5tG-7WFR8_k) which even wikipedia fell foul of. – PeterJCLaw Aug 28 '11 at 15:31

1 Answers1

2

When in doubt.. Always escape

RewriteRule ^hello\:world$ /hello/world.html [L,QSA]
Mike
  • 21,910
  • 7
  • 55
  • 79