更换域名后的301重定向解决方案(全站)
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.
- Log in to
cPaneland go to theRedirectsOption underDomainsCheck this image for better understanding. cPanel Redirects Option - Add the redirect. Check the Image for better understanding.
- Choose the Redirect type. (
301or302) - Select the domain from the drop-down. (Addon domain will show up too).
- do not add anything inside the
/. - type your new domain name inside
Redirects to - Select
www. redirection:option as per your requirement. - 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
filenameand new domainsfile namesare same. For exampleold-domain.com/somethingwill be redirected tonew-domain.com/somethingbut 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 folderusing cPanel File Manager or FTP Clients, except the.htacessfile to save space. Just keep the.htaccessfile. That's enough for you. But always keep a backup copy in case anything goes wrong.

浙公网安备 33010602011771号