HTACCESS: Redirect requests without www to www - example.com to www.example.com
Question by Compi | 2017-10-25 at 16:57
At the moment, my website is accessible via two different ways. A request for http://example.com as well as for http://www.example.com are both leading to my site - and that for each single page!
Therefore, my website is effectively reachable via two different addresses or domains. Gladly, I would like to redirect all calls to my domain without www to the domain with www. So, for example, the request for http://example.com should be redirected to http://www.example.com.
Can someone explain how to do that? I think the best way would be using and .htaccess file.
Related Topics
HTACCESS: Simplify URL
Tutorial | 0 Comments
Block specific IP Addresses with HTACCESS
Tip | 0 Comments
HTACCESS: Always Redirect Page/URL-Path to other Page
Tip | 0 Comments
Duplicate Content: Always Redirect Website to WWW
Tip | 0 Comments
HTACCESS: Crop Trailing Slash from the end of a URL
Tip | 0 Comments
Website Performance: Deliver JavaScript and CSS files compressed to reduce loading times
Tutorial | 0 Comments
HTACCESS: Force Download of specific File Types
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Just use the following Redirect in your .htaccess file (a file with the name .htaccess in the root folder of your website):
Of course, you have to change example.com to the name of your domain in order to use this example.
The Rewrite-Condition matches all cases not starting with "www.example.com" and then they will be redirected to http://www.example.com. With %{REQUEST_URI} you make sure that you do not lose any parts of the further URL. The HTTP-Status-Code 301 (Moved Permanently) tells every requester that your page can from now on only be found under the new address.
2017-10-25 at 18:38