I want to add www to my URL e.g example.com.au . Right now if I type www.example.com.au in the browser it gets changed to http://example.com.au . I want it to be http://www.example.com.au .

Below is the redirect rule in the server

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

What changes needs to be done to the above redirect rule so that www is added to the URL .


Canonical Hostnames Description:

The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following recipe. Solution:

For sites running on a port other than 80

RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]

And for a site running on port 80

RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]

Reference: RewriteGuide

  • Thanks Neuron for the quick response. But there is a slight edit. The domain name is actually example.com.au and not example.com – Zama Ques Aug 12 '15 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.