skip to Main Content

Recently purchased domain made the Primary Domain in my shared hosting plan.

Using the redirect option in Cpanel, olddomain.com home page is properly redirecting to newdomain.com home page as it should.

No files were removed or moved at all. Newdomain.com uses all the same WordPress files that olddomain.com did, and everything (including Htaccess, if that helps) is in /public_html.

Olddomain.com is now currently sitting as an ADDOn domain in Cpanel on same hosting plan.

Now how do I set up “one for one” 301 redirects for individual URLs? So olddomain.com/contact-us should redirect to newdomain.com/contact-us for example.

With olddomain.com being an AddOn domain, would it be as easy as adding ReWrite rules to the HTACCESS?

Truly appreciate your time!

2

Answers


  1. Chosen as BEST ANSWER

    All it took was adding a separate .htaccess file in the olddomain ADDON directory containing one-for-one 301 redirects as well as a ReWrite rule for the index.

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} (www.)?olddomain.com [NC]
    RewriteRule (.*) http://www.newdomain.com/$1 [R=301,NC,QSA,L]
    
    Redirect 301 "/blog-post/" "https://www.newdomain.com/blog-post"
    

  2. Yes, you can do it with .htacess as suggested by Anthony. I just make it little simpler for you.

    Solution 1:

    You can use this code to redirect the Old Domain Name to the New Domain Name. (Only domain redirect)

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^old.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.old.com [NC]
    RewriteRule ^(.*)$ http://new.com/$1 [L,R=301,NC]
    

    Solution 2:
    If you want to redirect particular Pages as well use the code below. (Don’t forget to add RewriteEngine on at the beginning)

    # 301 Redirect from OLD to NEW Page
    Redirect 301 /old-page https://www.new-domain.com/new-page
    

    You can add multiple redirects to redirect each page like

    Redirect 301 /contact-us https://www.new-domain.com/contact-us
    Redirect 301 /about https://www.new-domain.com/about
    Redirect 301 /blog https://www.new-domain.com/blog
    

    and so on….
    Redirect for the root domain to old-domain.com to new-domain.com can be done using

    Redirect 301 / https://www.new-domain.com/
    

    Solution 3:

    You can also add the following code to redirect the domain as well as the pages to the new domain using the following .htacess code.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^old-domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.old-domain.com$
    RewriteRule ^(.*)$ "https://www.new-domain.com/$1" [R=301,L]
    

    Solution 4:
    You can also do the same using cPanel.

    1. Log in to cPanel and go to the Redirects Option under Domains
      Check this image for better understanding.
      cPanel Redirects Option
    2. Add the redirect. Check the Image for better understanding.
    3. Choose the Redirect type. (301 or 302)
    4. Select the domain from the drop-down. (Addon domain will show up too).
    5. do not add anything inside the /.
    6. type your new domain name inside Redirects to
    7. Select www. redirection: option as per your requirement.
    8. Check the Wild Card Redirect box

    You are done. cPanel will write the .htaccess code for you.

    Remember the solution 3 and Solution 4 will only work if the
    old domain’s filename and new domains file names are same. For
    example old-domain.com/something will be redirected to
    new-domain.com/something but it can not be redirected to the
    new-domain.com/otherthing.

    If you have different file name for the new & old domain then use
    Solution 2 or don’t check on the www. redirection: option for Solution 4 and add the page name/file name on the / box (Option number 5).

    You can delete all the contents from the addon-domain.com folder
    using cPanel File Manager or FTP Clients, except the .htacess file
    to save space. Just keep the .htaccess file. That’s enough for you.
    But always keep a backup copy in case anything goes wrong.

    Hopefully, this is helpful for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search