Redirecting non www. to www?

KenX

Member
I am trying to redirect my forum to http://www.example.com but it isn't working.I edited my .htaccess and added this code
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [L,R=301]
But still it didn't work.Need help.
 
Thanks.

Just tried these. Works as you mentioned.
Okay, if you want main.com/addon (or anything /addon) to be redirected to just main.com, I think you would need to change that to
Code:
RewriteCond %{HTTP_HOST} !^main.com$ [NC]
RewriteCond %{HTTP_HOST} !^addon.com$ [NC]
RewriteRule ^(.*)$ http://main.com/$1 [R=301,N]
RewriteCond %{HTTP_HOST} ^main.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/$ [NC]
Rewrite ^(.*)$ http://main.com/ [R=301,L]
 
Okay, if you want main.com/addon (or anything /addon) to be redirected to just main.com, I think you would need to change that to
Code:
RewriteCond %{HTTP_HOST} !^main.com$ [NC]
RewriteCond %{HTTP_HOST} !^addon.com$ [NC]
RewriteRule ^(.*)$ http://main.com/$1 [R=301,N]
RewriteCond %{HTTP_HOST} ^main.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/$ [NC]
Rewrite ^(.*)$ http://main.com/ [R=301,L]
Tried this and it gave internal server error. :sick:
 
Okay, if you want main.com/addon (or anything /addon) to be redirected to just main.com, I think you would need to change that to
Code:
RewriteCond %{HTTP_HOST} !^main.com$ [NC]
RewriteCond %{HTTP_HOST} !^addon.com$ [NC]
RewriteRule ^(.*)$ http://main.com/$1 [R=301,N]
RewriteCond %{HTTP_HOST} ^main.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/$ [NC]
Rewrite ^(.*)$ http://main.com/ [R=301,L]
What's more important is to ensure www.addon.com and addon.com goes to addon.com and not get redirected to main.com/addon/
 
Okay try this one
Code:
RewriteCond %{HTTP_HOST} !^main.com$ [NC]
RewriteCond %{HTTP_HOST} !^addon.com$ [NC]
RewriteCond %{HTTP_HOST} !^www.addon.com$ [NC]
RewriteRule ^(.*)$ http://main.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.addon.com$ [NC]
RewriteRule ^(.*)$ http://addon.com/$1 [R=301,L]
The first part will only redirect requests which are not (!) main.com, addon.com or www.addon.com to http://main.com/
The second part will only redirect www.addon.com to http://addon.com/
 
Okay try this one
Code:
RewriteCond %{HTTP_HOST} !^main.com$ [NC]
RewriteCond %{HTTP_HOST} !^addon.com$ [NC]
RewriteCond %{HTTP_HOST} !^www.addon.com$ [NC]
RewriteRule ^(.*)$ http://main.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.addon.com$ [NC]
RewriteRule ^(.*)$ http://addon.com/$1 [R=301,L]
The first part will only redirect requests which are not (!) main.com, addon.com or www.addon.com to http://main.com/
The second part will only redirect www.addon.com to http://addon.com/
Thanks for your time.

Just tried this.

However www.addon.com and addon.com still redirects to main.com/addon/
 
Just did a thorough check on the domain control panel, dont think there is another redirection elsewhere.

I'm using cpanel.
Could you send me the actual URLs in a Private Conversation so I can try and diagnose?
(Presuming you don't really own main.com and addon.com. If you do, sell them and retire :) )
 
Top Bottom