Redirect WWW to non WWW, for primary domain, and parked domain

basketmen

Well-Known Member
Sep 9, 2010
128
1
66
Hi guys,

I already know basic Redirect www to non-www, using htaccess:

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





but how if we have parked domain too?

I already tried this but its not works, its says "The page isn't redirecting properly"

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^yourdomain2.com - Domain name registration Resources and Information. This website is for sale! [NC]
RewriteRule ^(.*)$ http://yourdomain2.com/$1 [L,R=301]




please share your knowledge, what is the best way for this?
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
The better option would be not to specify the domain name in the rewrite condition so that it redirects all www to non-www for that account:

Code:
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you also want all https traffic to go to non-www, then this should work:

Code:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]