Reputation: 10415
I want to redirect www.example.com to example.com. I've used cPanel to config my .htaccess file and added these lines to the end of the file:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]
However, www.example.com does not redirect to example.com.
What is wrong?
Upvotes: 0
Views: 32
Reputation: 46
Please try this..
Keep this one rule for all the sub-domains:
# rule for forcing www on main domain
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# rule for removing www on sub domains
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
Let me to know if its works.
Thanks
Upvotes: 1