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
    Posts
  • #18015
    Jaiji
    Participant

    Hi

    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 http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/ 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: the-old-domain.co.uk to newdomain.co.uk and redirecting:

    www.the-old-domain.co.uk/home/product-category/ to www.newdomain.co.uk/product-category/product-name/
    
    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.

    #18018
    AITpro Admin
    Keymaster

    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/(.*)$ http://www.newdomain.co.uk/product-category/product-name/$1

    Examples of what would be redirected using this code:

    the-old-domain.co.uk/home/product-category/product-1/ would be redirected to http://www.newdomain.co.uk/product-category/product-name/product-1/
    the-old-domain.co.uk/home/product-category/product-2/ would be redirected to http://www.newdomain.co.uk/product-category/product-name/product-2/

    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$ http://www.newdomain.co.uk/product-category/product-name/$1
    #18030
    Jaiji
    Participant

    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?

    #18031
    AITpro Admin
    Keymaster

    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?

    #18039
    Jaiji
    Participant

    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.

    #18041
    AITpro Admin
    Keymaster

    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.

    #18045
    Jaiji
    Participant

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

    #19098
    AITpro Admin
    Keymaster

    [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/ http://glutathione.md/immunocal/ (which works fine for all the pages), when I tried to do one for the main page: RedirectMatch 301 ^/ http://glutathione.md it caused all the pages to redirect back to http://glutathione.md.

    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,
    Dave

    #19099
    AITpro Admin
    Keymaster

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

    #19102
    Glutathione.MD
    Participant

    OK, awesome! That was easy enough…

    I simply changed the code to:

    RedirectMatch 301 ^/(.*)$ http://glutathione.md/$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!
    Dave

    #19104
    AITpro Admin
    Keymaster

    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):  http://forum.ait-pro.com/forums/topic/301-redirect-and-old-wordpress-dashboard/#post-12531  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:  site:example.com

    #19105
    AITpro Admin
    Keymaster

    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.

    #20250
    Goodvalley
    Participant

    [Topic has been merged into this relevant Topic]

    Hi,

    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 (www.oldsite.com) and a subdirectory subsite (www.oldsite.com/es). 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 (www.newsite.com) and (www.newsite.com/es). 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 ^/$ http://www.newsite.com

    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 www.oldsite.com or typing the www.newsite.com directly in the browser. It gets blocked. I’ve tried to do the same thing with the subsite’s main page (www.oldsite.com/es), with the same results, using: RedirectMatch 301 ^/es$ http://www.newsite.com/es

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

    #20253
    AITpro Admin
    Keymaster

    @ 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 ^/(.*)$ http://www.example.com/$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$ http://www.example.com/
    #20254
    Goodvalley
    Participant

    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 ^/$ http://www.newdomain.com/$1

    but this doesn’t seem to work. If you want to take a look, the old domain is http://www.skimatters.com and the new one is http://www.skireviewer.com

    Thanks,
    Carles

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