htaccess redirect old links to new domain

北慕城南 提交于 2019-12-31 05:22:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!