How do I redirect my site? non-www to www


A redirect is a simple way to automatically correct a users request to the correct page if you have moved the resource.

To make a redirect for a changed page, you need to add the following into a .htaccess file:

redirect <STATE> /old_page.name <FULLDOMAIN>/new_page.name

The <STATE> can be either

  • 301 - Moved Permanently - This and all future requests should be directed to the given URI
  • 302 - Temporary Redirect - In this case, the request should be repeated with another URI; however, future requests should still use the original URI.

So for example, if you wanted to permanently redirect www.example.com/smith.html to www.example.com/jones.html, you would put an .htaccess file in the web root folder of of your domain with the following:

redirect 301 /smith.html http://www.example.com/blog/jones.html

Use redirect to stop duplicate content on search engines

To prevent search engines being confused about your site, i.e. Is it http://yourdomain.com or http://www.your.domain.com, add the following to a .htaccess file

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

This will cause anyone who uses example.com to be automatically redirected to www.example.com


Was this answer helpful?

One email a month. Endless business benefits.

Don't miss out on WMTWWFY — the newsletter that keeps your website fast, safe, and visible.

« Back
Spinner
aluminium-anthropoid Security Check