Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain doesn't work without `www`

When I type in my domain name like without the www (like http://example.com), it doesn't work and gives error message. However, when I add the www to it (like http://www.example.com), it works.

Isn't it supposed to work both ways (with and without the www)?

like image 641
Digital site Avatar asked Apr 13 '12 04:04

Digital site


People also ask

Why is my website not working without www?

If your CNAME is set up, but your site doesn't load without www, you need to check that your A records are correct and then recreate the SSL certificate. To check if A records are correct: Go to whatsmydns.net.

Why does my domain only work with www?

Generally this occurs when a site is pointing to a service using the "WWW" cname instead of the "@" A Record or IP address. You may want to follow up with your store/site provider to see if they have another way to point your domain name to their service. Hi, My site won't load without entering www.

Is www required for a domain?

It's actually not necessary to use WWW in URLs. It exists for just one purpose—to identify the web address. This is not the case with other important URL signifiers, such as a File Transfer Protocol (FTP) server (ftp) or news server (news). As such, WWW may be classified as a subdomain of a larger website.

How do I point my domain without www?

Without the 'www', you must set your root (non-www) domain DNS A-record to point at your web server's IP address. This can be too rigid if you encounter availability or performance issues; the A-record is fixed and can take a day or two for changes to propagate.


1 Answers

All you need is to add the following code to your root .htaccess file:

RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
like image 150
Digital site Avatar answered Sep 19 '22 12:09

Digital site