Enquiry Email Form

Here’s a piece of htaccess code which you can use to 301 redirect an old website onto a new domain, while preserving the same URL structure for every page. Obviously, you will need to copy all the same files across, and DB, if it’s determining smartessaywriter the URL’s.

So, for example:

Old website: http://oldwebsite.co.uk will 301 redirect to http://newwebsite.co.uk
Old website page: http://oldwebsite.co.uk/page1.html will 301 redirect to http://newwebsite.co.uk/page1.html
Old website page: http://oldwebsite.co.uk/page2.html will 301 redirect to http://newwebsite.co.uk/page2.html

The code

1
2
3
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^oldwebsite.co.uk 
RewriteRule (.*) http://newwebsite.co.uk/$1 [R=301,L]
  1. Cna
    10/06/2014

    I’ve a similar problem which is a lil bit different than this
    as you said this code redirects urls which contain an extension like your examples
    oldwebsite.co.uk/page1.html will redirect to newwebsite.co.uk/page1.html

    but what if I wanted to redirect oldwebsit.com/test-page-link to newwebsite.com/test-page-link

    Is there a way to do so??? I’ve looked up everywhere and seems no one has mentioned any sullotion to such a problem…

  2. adm1n
    09/02/2015

    The code in my example should also do that- have you tried it? 🙂

Learning & sharing

This is where we store some of our Web Development thoughts, tips and tricks for both our own uses and for others to learn from. Sharing is caring.

Please feel free to contribute to our blog posts; perhaps even teach us a few tricks of your own. We'd love to hear your thoughts.



X