Enquire

htaccess- Redirect Entire Website To New Domain While Preserving URL Structure

htaccess fun

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]

Comments

  1. Cna spoke on 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 spoke on 09/02/2015

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

Leave a reply

Your email address will not be published. Required fields are marked *

X