问题
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
回答1:
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.
回答2:
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]
来源:https://stackoverflow.com/questions/23017137/htaccess-redirect-old-links-to-new-domain