Forum Moderators: phranque

Message Too Old, No Replies

Remove spaces with httpd.conf RewriteRule

         

chtaylo2

8:18 pm on Aug 10, 2011 (gmt 0)

10+ Year Member



Hi,

I have a webserver which multiple CNAMES bouncing threw.

I have this rewrite setup:

RewriteEngine On
# Support DEV
RewriteCond %{HTTP_HOST} ^support-dev [NC]
RewriteRule ^/(.*) http:/www-dev.domain.com/it/searchsc.shtml?q=$1 [R,NC]


Currently if someone types in:
http:/support-dev/microsoft outlook redirects to: http:/www-dev.domain.com/it/searchsc.shtml?q=microsoft%20outlook

I would like to remove the SPACES so:
http:/support-dev/microsoft outlook redirects to: http:/www-dev.domain.com/it/searchsc.shtml?q=microsoftoutlook

Any idea how I can do this?

Thanks!

g1smd

8:21 pm on Aug 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's 1000 prior examples in the WebmasterWorld forum: [google.com...] :)

Post example code and any problems you are having.

chtaylo2

8:27 pm on Aug 10, 2011 (gmt 0)

10+ Year Member



I've been looking for the last 3 hours and all are talking about removing spaces and replacing with dashes or %20, etc. I've also haven't had luck since I have multiple RewriteCond how to make it only apply to the one which matches.

The example code I tried is this:

RewriteRule ^/([^\ ]*)\ (.*)$ $1$2 [N]

but it didn't work out, keep getting an internal server error.

chtaylo2

8:49 pm on Aug 10, 2011 (gmt 0)

10+ Year Member



I got it. Ended up using this


RewriteRule ^([^\ ]*)\ (.*)$ $1$2 [N]


Thanks for the help

lucy24

9:43 pm on Aug 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Be very, very careful with the [N]. It doesn't simply mean "run this rule over and over until the request rinses clean". It means "go back to the beginning of the htaccess and try everything again".

chtaylo2

7:42 pm on Aug 11, 2011 (gmt 0)

10+ Year Member



Great. thank you for the tip!