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!
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.
cPanel
and go to the Redirects
Option under Domains
Check this image for better understanding.
cPanel Redirects Option301
or 302
)/
.Redirects to
www. redirection:
option as per your requirement.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 domainsfile names
are same. For exampleold-domain.com/something
will be redirected tonew-domain.com/something
but it can not be redirected to thenew-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.