views:

500

answers:

3

I need to set up some RewriteRules to redirect a URL which has a space in it. I've tried this:

RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L]

... but it doesn't work. Putting in a space instead of %20 causes a 500 Internal Server Error. How do I add a space?

+1  A: 

Ah, I've found a solution: use the regex style to show a space:

RewriteRule ^article/with\sspaces.html$ ...

Though, I suspect that this would match all the other whitespace characters too (tabs, etc), but I don't think it's going to be much of a problem.

nickf
+8  A: 

Try putting a \ in front of your space to escape it.

RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]
Beau Simensen
cheers! I shoulda figured it'd be something simple like that.
nickf
+6  A: 

You can just escape the space with a \

RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]
Rich Adams