views:

101

answers:

1

This is from a .htaccess located under /~new/

# invoke rewrite engine
    RewriteEngine On

# force domain.com to www.domain.com

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

When accessing http://domain.com/~new/hello, it is being rewritten to http://www.domain.com/hello

The www. is being added in like it should, but for some reason it is ignoring the /~new/ subdirectory.

Does anyone know what may be causing this? FYI, there is a .htaccess in the TLD but it is empty. I know I could tack on /~new/ to the regex replacement string, but I'd prefer a generic solution (for portability) and I am not sure why it's stripping it out in the first place. I have also tried playing around with RewriteBase but could not get it to work.

Thanks

+1  A: 

I think normally the {REQUEST_URI} would be in your rewrite rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ www.%1.%2%{REQUEST_URI} [R=301,L]
AaronLS
I had to insert http:// before the www in your RewriteRule and it worked! Also, because my site is on an Australian domain, I changed your (com|com/) to (com.au|com.au/). Thanks!
alex
Actually, I ended up changing that last part to ([a-z\.]{2,6}
alex