Site5 - Built For Designers & Developers MENU
Home  ›  Apache  ›  Apache: How to set your domain to redirect to WWW by default

Apache: How to set your domain to redirect to WWW by default


Add the below to your .htaccess file in order to have your-domain redirect to www.your-domain. Just make sure where it says “” to fill in your domain on both lines 2 and 3.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$$1 [R=301]

Why would you do this? It makes your site nice and clean and loading off In addition this avoids the duplicate content penalty from search engines, because otherwise your site appears to have a site at “” and at “”.

Still have a question? Or need help?
If you need technical support with your account, please email us or chat live with a representative.


  • Perfect. Thank you for this. But I have one question though. In Firefox and Chrome they both show but in IE it shows How can I make IE show the same. Thanks again.

  • So does this mean one cannot use a non www domain for google page speed?


    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^(.*)$$1 [R=301]

    • Hello Al,

      I hope this reply finds you well!

      You are correct. The non-www based domain cannot be pointed at the Google PageSpeed CNAME and in turn all non-www based traffic would need to be redirected to your www based domain in order for that traffic to be routed through Google PageSpeed.

      The htaccess file in this article (located above) will help you redirect the traffic from your non-www based domain to your www domain.

      If you have any questions, please feel free to leave a comment here, or if you prefer, you can open a ticket with our support department through Backstage.

      Happy Hosting!

  • Great, I had the problem in this but now it resolved, thanks team site5 :)

    • Hi Nicolas!

      Fantastic! You’re welcome and glad to hear that your problem was resolved!

  • When using this, public_html is inserted into the URL (presumably related to running a rails app). Any suggestions?

    redirects to

    which returns a 404

    • Hi Jon!

      That is an odd issue indeed and it does sound as if the redirect rules need a bit of tweaking to make them work properly. If you would please open a ticket through your backstage panel, our team will be glad to take a look and find a working combination of redirect rules for you!

Money Back Guarantees