htaccess redirect all pages AND specific pages (6 posts)

  1. Dave333
    Posted 6 years ago #

    I've moved my blog to its own domain and now need to redirect all the visitors to the new domain via an .htaccess file.


    has moved to


    I understand that I can put a redirect code in the .htaccess file in this location: http://www.OldDomain.com/blog/ so that all visitors get redirected to the front page of the new domain, but it would be most ideal if the visitors could be redirected to the particular page they are trying to get to instead.

    The reason this is important is that I have a lot of pages that are heavily linked to from many other sites. I am concerned about these links now being broken having moved the blog to it's own domain.

    So is it possible to do this somehow:


    gets redirected to


    Is this possible??

    If I have to write a line of code for each page, then I would for the most visited 10 or so but obviously can't do that for all pages. So if I had to, could I redirect certain pages with a line of code for each of the most popular ten or so then have all other pages redirect to the front page of the new domain?

    Or is there a smarter way of redirecting visitors to the exact page they wanted to visit on the new domain?

  2. Samuel B

    Posted 6 years ago #

  3. Dave333
    Posted 6 years ago #

    Thanks samboll,

    This solution requires that I have a duplicate blog and database, one in the new location at:


    and the old one at:


    I moved the old domain over to the new host so I could set up the old blog in that folder and then use the redirection plugin but I'd rather deal with this simply, preferably by using the htaccess file.

    Putting it simply, is there a way of redirecting the visitor who is trying to go to http://www.OldDomain.com/blog/StoryFromFebruary by automtically removing this first part of the address:


    and replacing it with the new address:


    so that the result is they are taken to this addresss:


    Is that possible via the .htaccess file?

    I've placed a .htaccess file in the http://www.OldDomain.com/blog folder that has this in it:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^OldDomain/blog$ [OR]
    RewriteCond %{HTTP_HOST} ^www.OldDomain/blog$

    RewriteRule ^(.*)$ http://www.NewDomain.com/$1 [R=301,L]

    Is that all I need to do to achieve what I've described above?

  4. Dave333
    Posted 6 years ago #

    I've solved it.

    That code in the .htaccess file was not working.

    Instead, I put the following code into a .htaccess file in the root folder:


    RedirectMatch 301 /blog(.*) http://www.NewDomain.com$1

    Now even if a visitor links to my blog from an old link they will stil arrive at the same page on the new domain. i.e.:


    will be translated to


    I hope this helps someone else.

  5. betwixt
    Posted 6 years ago #

    It did help me! Thank you very much!

  6. 2010
    Posted 5 years ago #

    Cheers Sam,

    Used the redirection plugin and were redirecting.

Topic Closed

This topic has been closed to new replies.

About this Topic