Redirect to one central domain - htaccess

If you would like to 'redirect' all your users to a central domain (for example if you would like all users to browse your site with the www or you have several parked domains) then paste the following code into your .htaccess file (normally located in the root) - works on Linux servers with cPanel.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} =mikestreety.co.uk
    RewriteRule ^(.*)$ http://www.mikestreety.co.uk/$1 [L,R=301]
</IfModule>

Change the domain where appropriate. In English this says if its not mikestreety.co.uk then redirect to mikestreety.co.uk.

This is especially good for SEO purposes as it means google does not see duplicate content if you have several parked domains, or if you have flash on your website which generally requires the www. prefix to work

This website is currently having a full content audit - apologies if some of the code or content looks a bit funky!
Web

View this post on Gitlab

You might also enjoy…

  • Limit Items (e.g. News posts)

    Posted on 10th March 2011.

    If you would like to limit the amount of items coming out of an array (for example the first 5 news items)

  • Get an 'Even' Class

    Posted on 16th February 2011.

    This PHP statement applies class="even" to every other element when in a loop.

Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.