Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite matching spaces?

mod_rewrite matching

         

l008comm

7:32 pm on May 16, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



How does one get mod_rewrite to match a space in a url? The spaces are converted into '%20'. ([a-zA-Z0-9]+) does a perfect job of matching pretty much any directory name on my server, except ones that contain spaces. No one seems to know what to do with this.

Thanks
John

jdMorgan

7:43 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One relatively foolproof way is to use

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^%]*)\%20([^\ ]*)\ HTTP/
RewriteRule .* /%1-%2 [L]

This will detect and replace the space with a hyphen. It works because {THE_REQUEST} contains the actual client request header, before any unencoding is done.

See related thread: [webmasterworld.com...]

You can also try using "\ " or "\s" in RewriteRule -- but support seems to vary by server.

Jim

l008comm

8:14 pm on May 16, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



"\ " seems to work, thanks!