You are here

Redirect non www to www or vice versa (main domain, subdomain)

Last post
4 posts / 0 new
Dan
Dan's picture
Offline
Last seen: 15 hours 50 min ago
Joined: Jun 2012
Points: 377

Redirect non www to www or vice versa (main domain, subdomain)

@danpros wrote:

There is a project that requires me to make the following domain redirection:

  • Redirect all users to access the site WITHOUT the 'www.' prefix for all subdomain.
  • Redirect all users to access the site WITH the 'www.' prefix for main domain only.

To fulfill this purpose, I simply add a few lines of code to the htaccess file.

RewriteEngine on

# Redirect the 'www.' version of the subdomains.
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com [NC]
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]

# Redirect the non 'www.' version of the main domain.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Read more Redirect non www to www or vice versa (main domain, subdomain)

Dan,
Follow me danpros and danbz.

Offline
Last seen: 5 days 4 min ago
Joined: Feb 2013
Points: 149

So you do 301 redirect Dan. I

So you do 301 redirect Dan. I have read that it will drive links on the old website to the new one, so the new one has the same links as before. It's good for permanent move.

luxiezas's picture
Offline
Last seen: 19 hours 46 min ago
Joined: Feb 2013
Points: 76

think

I think you better to choose Redirect all users to access the site WITH the 'www.' prefix for main domain only Dirol

Septictankbiorich.comBiotech System
SeptictankbiorichBioRich, Biotech, Biofil
Surya Utama FibertechFibreglass

kanghari's picture
Offline
Last seen: 1 month 6 days ago
Joined: Nov 2012
Points: 79

Actually, the good life www

Actually, the good life www or no www, I am still a bit confused