Please forgive what may sound like a similar question to what has been asked, however, I am VERY new to XAMPP and Apache and I have tried all possible combinations of the Rewrite Rules mentioned in other threads, which I have placed in the httpd.conf
, httpd-default.conf
and also in .htaccess
and I simply cannot get the rewrite rules to work.
I simply want to redirect example.com
to www.example.com
. Please note that my redirect from HTTP to HTTPS is working 100%, so if someone can please advise on exactly where I should place the rewrite rule, and which one to use, to force non-www to www, I would be most appreciative.
I have full access to the server so I can edit either .conf
or .htaccess
files. Also I have checked and the part in httpd.conf
that allows overrides to read the .htaccess
files is enabled. The .htaccess
file is currently in the same folder where my website lies. Just to add, I don’t get any error, it just says the page has timed out if I type in example.com
, if I type www.example.com
then the page loads as expected.
2
Answers
Try this in your .htaccess file:
Replace example.com with your url.
This is a DNS or server config error. The request is not even reaching your server, or your server is not responding to the request. (So any attempt to implement a redirect will naturally fail.)
A quick check of the DNS for
example.com
andwww.example.com
shows they are pointing to different IP addresses (you have anA
record configured for each). Theexample.com
host is 1 digit different and would appear to be incorrect (the IP address does not respond to requests, hence the "time out").Instead of having a separate
A
record for each hostname. If the www subdomain is supposed to point to the same site as the domain apex (ie.example.com
) then configure aCNAME
record instead that pointswww.example.com
toexample.com
(this is not a "redirect").You then need to ensure that your server will accept requests to the non-www hostname. For example:
(It’s possible you have the
ServerName
andServerAlias
reversed – which is "OK".)And the SSL cert needs to cover the non-www hostname (it does).
You can then implement your non-www to www HTTP redirect as mentioned.