简体   繁体   中英

htaccess redirect old links to new domain

I changed my site domain, and want to redirect old urls to new domain

(note: instead of numbers 93, 54 maybe any digit number exists) the old urls are:

http://olddomain.com/
http://olddomain.com/45
http://olddomain.com/p/93

the new urls are:

http://newdomain.com/
http://newdomain.com/45
http://newdomain.com/p/93

I tried this at htaccess:

RewriteEngine on

RewriteCond %{REQUEST_URI} 
RewriteRule  http://newdomain.com/

RewriteCond %{REQUEST_URI} (\d+)/
RewriteRule (\d+)/ http://newdomain.com/$1

RewriteCond %{REQUEST_URI} p/(\d+)/
RewriteRule p/(\d+)/ http://newdomain.com/p/$1

but not worked :(

In addition, there is a choice at cpanel caller Redirects can I redirect the old links to new by using it. thanks for help

If it's just those three you want to redirect, you can do it with an OR in your regex. The below should work.

RewriteEngine On
RewriteRule ^/(45|p/93|$)$ http://newdomain.com/$1 [R,L]

This should work:

RewriteEngine On
RewriteRule ^(.*) http://newdomain.com/$1 [R=301]

It will redirect all pages from the old website to the new website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM