Rewrite or Redirect old website domain to new domain with new url structure

Home Forums BulletProof Security Free Rewrite or Redirect old website domain to new domain with new url structure

Viewing 15 posts - 1 through 15 (of 36 total)
  • Author
  • #18015


    First, thanks for an awesome plugin, I use it on all of my live sites. Now, apologies if this is covered elsewhere, I’ve been hunting around for hours with different permutations fo what I think is the right question and can’t find an example of this which makes any sense to me, the more I hunt the more confused I’m getting.

    I’ve redeveloped a site, with a new URL structure and a new domain. I have set up twenty 301 redirects via cPanel for old pages to go to their new equivalents. Everything works.

    When I add the redirect code to the secure htaccess file (after activated BPS) as per this post the redirects all fail. I assume it’s because of the change in URL structure and therefore the code needs to go into a different place in the file.

    My host has advised that the code needs to go above #BEGIN WordPress so evidently using the CUSTOM CODE BOTTOM text box is not correct.

    As you can tell I am new to all this. How do I proceed with BPS? Please confirm if the code below is correct (and if not could you provide correct versions of these two examples please) and where/how I should add it to the secure file.

    Here are two examples, redirecting the home page from: to and redirecting: to
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^the\-old\-domain\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.the\-old\-domain\.co\.uk$
    RewriteRule ^/?$ "http\:\/\/www\.newdomain\.co\.uk\/" [R=301,L]
    RewriteCond %{HTTP_HOST} ^the\-old\-domain\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.the\-old\-domain\.co\.uk$
    RewriteRule ^home\/product\-category\/$ "http\:\/\/www\.newdomain\.co\.uk\/product\-category\/product\-name\/" [R=301,L]

    Many thanks.

    AITpro Admin

    First off, to be technically correct what that code is doing is rewriting URL’s and then redirecting them with the the R flag in a RewriteRule.  Rewriting would need to occur in the WordPress Rewrite Loop Start code for that type of rewrite code.  A typical redirect such as RedirectMatch 301 could be added anywhere in an htaccess file.

    This RedirectMatch code below will redirect all old posts on the old site under the product-category category to the new site’s product-category category and the product-name category (not sure what product-name is – a single post or another category?) and all posts from the old site will match/redirect to their exact matching post URI on the new site by using a backreference $1

    Notes:  This RedirectMatch code would need to be in the old site’s htaccess file since you are redirecting from the old site to the new site. This code will only work correctly if the old post names / URI’s are identical. ie URI /product-1/ on old site is also /product-1/ on the new site.

    RedirectMatch 301 ^/home/product-category/(.*)$$1

    Examples of what would be redirected using this code: would be redirected to would be redirected to

    If the old site is an HTML site and these old posts are HTML files then you would need to use this code below to redirect the old HTML files to the new WordPress posts.

    RedirectMatch 301 ^/home/product-category/(.*).html$$1

    Many thanks for that. A few clarifications though:

    The old site no longer exists in any form anywhere. Both domains are now pointing to the new site, which is a complete redevelopment and bears little relationship to the old one other than subject matter, it has a totally different URL structure and also exists on a new host server. In this case WordPress is mainly in use as a CMS rather than a blog and each old page needs an individual redirect to its new equivalent – there are no matches. The redirects are so that anyone visiting a bookmarked page will be pointed to the new version on the new site. The two examples I gave are actual redirects (re-worded but structurally identical) in place already and working fine (without BPS activated).

    I assume this would change your answer?

    AITpro Admin

    Oh ok I assumed you wanted to redirect old links that have been indexed by Google and exist in Google search results.  If these are just internal site redirects then you can do them from within the new site.  Obviously you cannot reference an old site on the new site in the new site’s htaccess code because that would not work of course.  Before I answer your question about doing internal website redirects I want to know what you mean by a “bookmarked page”.  Do you mean a bookmarked page in someone’s Browser?  If so, then the link will point to the old site and the only way to do a redirect to the new site would be to create an old site folder, add an .htaccess file to redirect someone to the new site (or you could do redirects/forwarding from the Server itself).  ie domain foo is forwarded (A record) to domain bar. ie if someone flies to Paris (the old domain) then they would have to catch a plane from Paris to somewhere else (the new domain).

    This is a better question to ask so that I know what you have done up to this point.  What happens / where are you sent after you click on a Bookmark to one of the old site’s pages/posts?


    What I’m wanting is to set it up so that should someone enter an old URL in their browser (or access a bookmark with an old URL), they will be taken to the new page, or the nearest equivalent. Each page needs a separate redirect. As I say I already have htaccess code in place which does this – 20 redirects, two of which I put as examples above (with re-worded but otherwise identical URLs i.e. the old domain is hyphenated, the new one is short and one word). All the redirects currently work as required.

    Both the old domain and the new one point to the new server, and are administered by the same new host, but only the newly developed site exists, and it’s being promoted with the new domain. The newly redeveloped site features a smaller, more focused set of products and a totally different e-commerce setup, and a number of the old pages and products no longer exist, so RedirectMatch is not the way to go. The site sells artisan chocolates, currently when you enter the old URL for organic chocolate bars, it takes you to the new page for organic chocolate bars.

    As far as I can see, I just need to know how and where to enter the existing redirect code (which as I say works fine) into the secure htaccess file when I activate BPS. I’d like to add it as custom code but need to know how/which box to add it to.

    AITpro Admin

    Ok if you have working code and it just needs to be integrated into or replaces the WP Rewrite Loop Start code then you would do these steps:

    1.  Add your customized WP Rewrite Loop Start code in this BPS Root Custom Code text box:  CUSTOM CODE WP REWRITE LOOP START: Add www to non-www/non-www to www code here
    2.  Click the Save Root Custom Code button.
    3. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.


    OK cool that’s it, many many thanks for your time and patience.

    AITpro Admin

    [Topic manually moved to this relevant Topic]

    Hello AITpro!

    First of all, your plugin is working great and all the updates you folks have been doing over the last year have made things much easier and much better. Thank you and keep up the great work!

    I contacted you a little over a year ago regarding a redirect issue and you helped me solve it. Today, I have a new issue and hope you can once again help me get this right.

    Due to new trademark restrictions, the company I work with is forcing everyone using the product name or company name in their url to shut the sites down. So, I have had to buy a new domain and have since reloaded everything. So, now I want to 301 the old site to the new site to maintain my SEO work. All the pages are the same, everything is the same… only the main domain is changed. It’s a combination of Multisite and also other external WP installs, along with some static HTML pages in the mix.

    So, the problem is that after doing over 200 individual redirects, such as: RedirectMatch 301 ^/immunocal/ (which works fine for all the pages), when I tried to do one for the main page: RedirectMatch 301 ^/ it caused all the pages to redirect back to

    My question are:
    1. Is there an easier way, rather than over 200 individual redirects?
    2. If there is not an easier way, can you please provide the correct code for also redirecting the main page?
    3. Last year when I first switched the site over to WP, I set up all the redirects from the old HTML site. Can I delete all those redirects now, or should I just leave them and all all the new redirects to the new domain below them?

    Thank you,

    AITpro Admin

    @ Dave – see the examples above in this Forum Topic.


    OK, awesome! That was easy enough…

    I simply changed the code to:

    RedirectMatch 301 ^/(.*)$$1

    added it after the rest of the redirects that where originally there and everything goes where it is supposed to go, including all the PDF files (which I didn’t expect).

    One last question though:
    How do I access the administration section of the old site now to do updates, etc.? Obviously if I try to access the login or wp-admin sections, they also get redirected. So, does this mean I need to change the .htaccess in FTP to do updates or will it be safe to just let the domain sit as it is and just keep paying the hosting/domain fee until I find another use for the site?

    Further to that, how long do you recommend I leave the original site online as it is to avoid hurting my SEO?

    Thank you again!

    AITpro Admin

    Yep htaccess code is actually really easy to use once you understand the basics and htaccess code can do a lot of really cool/neat things.  BPS is pretty much just doing only practical workhorse stuff with htaccess code.

    You can use this code to allow logins to the site and have everything else be redirected (add your redirect code after this htaccess code in your root htaccess file):  I would say leave the old site for 1 month or maybe 2.  You can check Google by using the “site” operator search to see how many of your posts/pages are still showing old URLs and of course check the new URLs.  Example:

    AITpro Admin

    Hmm I bet there is a way to speed this up.  Google does allow you to de-index search results.  So check into possible ways to speed the whole process up.  There may even be a way to do something directly in Google Webmaster Tools.


    [Topic has been merged into this relevant Topic]


    I’ve been using BulletProof Security for 3 years now without a single problem until now. I’ve been looking for an answer to my problem in the Forum but I haven’t found it. I have a WordPress Multisite Installation with a main root site ( and a subdirectory subsite ( One is an English site and the sub-site is the same but in Spanish. I’ve developed a new site with a different domain ( and ( The internal structure is slightly different, so I’ve had to redirect each page/post manually with RedirectMatch 301. I can do it either from within my SEO plugin or with the Custom Code Editor in BPS. No problem with that, it works perfectly.

    But the problem comes when redirecting only the old homepage to the new homepage. It just doesn’t work. The browser says “the page is not redirecting properly” and “the browser is redirecting the request in a way that will never be completed”, so it’s unable to go to the new url. Not a 404 or 500 error. The same thing happens from a mobile phone or another computer.

    In the Custom Code Edtor, I write: RedirectMatch 301 ^/$

    Of course, then I go to the Security Modes and Activate Root Folder BulletProof Mode so everything should be ok. But then the browser can’t reach the new adress both from the or typing the directly in the browser. It gets blocked. I’ve tried to do the same thing with the subsite’s main page (, with the same results, using: RedirectMatch 301 ^/es$

    Can you help, please?
    Thanks very much in advance.
    Carles Goodvalley

    AITpro Admin

    @ Goodvalley – using code like this below would redirect all old site pages and posts to identical matching pages and posts with the same structure.  So since you have a different structure then you can either try to redirect just the index.php file to the new site individually or maybe there is a better way to redirect everything from old site to new site.  I would need to know the old structure and the new structure to give you that code.

    RedirectMatch 301 ^/(.*)$$1

    Redirect just the index.php file from the old site to the new site, but this may not work due to how WordPress rewrites index.php

    RedirectMatch 301 ^/index.php$

    The new structure doesn’t have anything special to it. It’s simply that there are pages/posts with different names, some of them don’t exist anymore, there are new names to some pictures, etc. That’s why redirections for every element are done manually for each one of them.  The only problem appears when trying to redirect ONLY the homepage to a new homepage in a new domain. Both are created with WordPress, so no index.html, etc.

    What I’m doing is:

    RedirectMatch 301 ^/$$1

    but this doesn’t seem to work. If you want to take a look, the old domain is and the new one is


Viewing 15 posts - 1 through 15 (of 36 total)
  • You must be logged in to reply to this topic.