• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Use backslash on basic rewrite?

gemini181

New Member
Sorry to ask the most basic question, but I've seen this done both ways.
For the simple .htaccess rewrite (eliminate www.) should I use the backslash?

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]

or

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

On one host they both seem to work, so which is better to use 'all the time'?

Thank you
 
I've always had trouble with mod_rewrite. I can never figure it out, but sometimes it behaves differently on different hosts. Also, just a note, those are slashes, not backslashes.

I believe the first example you have provided is more correct, at least according to the examples provides here : http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html (near the bottom).

Though, that said, I took a look in my config and I used:

RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://domain.com/$1 [L,R=301]


So I don't know. I'd say test it out on your current host, and whatever works best, use it. Be sure you aren't directing users to http://domain.com//
 
Last edited:
Back
Top