• Resolved mrppp

    (@mrppp)


    Looking to move a site and wanted to know if following code would 301 redirect each page to the new page i.e site1.co.uk/page1 to site2.co.uk/page1 and site1.co.uk/page2 to site2.co.uk/page2 and so on rather than 301 redirect any old page to the main page of new site?

    RewriteCond %{HTTP_HOST} ^.*oldsite\.com$ [NC]
    RewriteRule ^(.*)$ https://newsite.com/$1 [R=301,L]

    https://www.ads-software.com/plugins/bulletproof-security/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author AITpro

    (@aitpro)

    Simpler method:
    In the oldsite.com .htaccess file you would add ONLY this code below and no other code in that .htaccess file for the oldsite. Click the Google link below to see what Google recommends when doing something like this and of course check and recheck things to make sure everything is working correctly.
    https://support.google.com/webmasters/answer/83105?hl=en

    Source: https://stackoverflow.com/questions/1945568/htaccess-redirect-all-pages-to-new-domain

    Here, this one redirects everything after the domain name on the url to the exact same copy on the new domain url:

    RewriteEngine on
    RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]

    www.olddomain.com/somepage.html?var=foo redirects to www.newdomain.com/somepage.html?var=foo

    Additional recommendations: After you have tested that everything is working correctly then still leave the oldsite the way it is for a few days and maybe a week just in case you need to roll things back. Then after that time period is up you can delete the old sites files and database and only leave the .htaccess file so that it will continue to redirect to the new site.

    Thread Starter mrppp

    (@mrppp)

    Thanks i will put a robots block in new site until it functions, that way old site can continue while i test.

    *Additional recommendations:
    You mean still add the htaccess code above but leave site functioning?
    will old site function with just this in htaccess?

    RewriteEngine on
    RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]

    Plugin Author AITpro

    (@aitpro)

    You would be leaving the old site just in case you need to roll everything back. The old site would redirect everything to the new site so it would just be sitting there in case you need to roll everything back. This is just a precautionary measure so that you don’t end up doing something like this.

    Example Scenario: You delete the old site and then find out there is a problem with the new site. something doesn’t work or there is some other problem that you need to get the old site back up. Since you already deleted the old site you will now have to restore it from backup. not a big deal, but why add the additional headache.

    Thread Starter mrppp

    (@mrppp)

    Understood, so if i reverted back upload original htacces for it to function.

    Plugin Author AITpro

    (@aitpro)

    Yep, exactly. It would be a simple “on/off switch” thing. ??

    Thread Starter mrppp

    (@mrppp)

    cheers, now to work out moving the darn think

    Thread Starter mrppp

    (@mrppp)

    hope you dont mind me checking things with you.
    I have used duplicator and have site running local, so will run on new site now.
    Few questions.
    1 If i put robots.txt in new site `User-agent: *
    Disallow: /`

    this will prevent crawling by good bots so i can test fully without having two sites indexed?

    2) when i,m happy do i just backup the htaccess created by BP in my root directory of old site, then delete and add the redirect htaccess above.
    3) remove robots txt in new site

    Plugin Author AITpro

    (@aitpro)

    WordPress has a built-in option setting that you can use instead of creating a robots.txt file to tell search engines not to index a website.

    Settings >>> Reading >>> Search Engine Visibility checkbox Discourage search engines from indexing this site

    Thread Starter mrppp

    (@mrppp)

    oh yeah will do that then.

    Plugin Author AITpro

    (@aitpro)

    Also I recommend using a WordPress virtual robots function instead of a robots.txt file IF in the future you want to exclude a certain folder or URL from being crawled and indexed. Or you can do this same thing in a sitemap plugin like the Google XML Sitemaps plugin by choosing posts and pages to exclude from being added to your sitemap.xml file.

    https://forum.ait-pro.com/forums/topic/wordpress-robots-txt-wordpress-virtual-robots-txt/#post-6523

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘custom htacces redirect’ is closed to new replies.