I want a rather simple feature, I want my website to work when someone puts a www. before my domain name. My preference is to redirect all http://www.
requests to http://
without anything complicated.
I have tried two methods to this and neither works desirably. The first option was to simply add this following rewrite engine command in the site's .htaccess
(which, for the record, I confirmed was working)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
I tried numerous variations of this code, and none of them do a thing. Even after resetting my browser cache, accessing through Tor, if I enter my website with the www.
prefix then it simply doesn't load and Firefox gives me a "server not found" error.
The second thing that I have tried is to remove all rewrite codes and simply add the DNS record A, with the host www
that points to my IP address. After waiting a little bit, the website was now working! However, it was incredibly inconsistent, because if I were to access www.example.com
then it would remove the www.
, but if I went to www.example.com/page.html
then it wouldn't remove it (but it'd still work). Another weird issue is that if I typed www.example.com/folder/page
, it'd send me to www.example.comfolder/page
.
Does anyone have any advice on what should I do or what I could be doing wrong?