Forum Topic: Unable to use the “Remove WWW” Canonical URLs Rule

Forum: .htaccess Forum : Redirecting • Posted by Dave Adams • Updated:

For some reason I try to use the code to remove the WWW and I get the error of “The webpage at http://dscommunications.ca/ has resulted in too many redirects.”

However when I go the other way and require the www. It works.

I don’t know why.

By the way, here is a neat website for testing redirects:

http://www.searchmasters.co.nz/redirect-check/

3 Replies to “Unable to use the “Remove WWW” …”

Posted by Jeff Starr

Hi Dave,

Can you post the code you’re trying and I’ll take a look..

Thank you for the link – added to the Security Tools

Posted by Dave Adams •

I am simply using the code from your WordPress template. The code below is what is not working and sending everything into too many redirects. Perhaps I should be putting the full domain name maybe?

# Remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Posted by Jeff Starr

I tested the code again and everything seems to be working fine, so it could be related to something else, such as other .htaccess directives, scripts, Apache version, and so on.. but rather spend time trying to troubleshoot, here is an equally effective method that requires a bit of editing:

# remove www
RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]
RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]

Just replace the domain name with your own and it should be good to go. Let me know if any further issues, glad to help.