.htaccess 需要htaccess将所有url从旧子域重定向到新子域

hgqdbh6s  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(203)

在根目录中的代码已经工作(例如):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.co.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.co.uk [NC]
RewriteRule ^(.*)$ https://www.NEW111NEW.com/$1 [L,R=301,NC]

现在我需要重新导向子网域(例如):

从:https://info.oldsite.co.uk/blog/some-blog-post-a
至:https://info.NEW111NEW.com/blog/some-blog-post-a
我试了- 1(不工作):

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^info.oldsite.co.uk [NC]
RewriteRule ^blog/(.*) http://info.NEW111NEW.com/blog/$1 [L,R=301,NC]

还尝试了-2(不工作):

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(info\.)?oldsite\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://info.NEW111NEW.com/blog/$1 [R=302,L]

---更新---
当尝试-3时(部分工作):

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^info\.oldsite\.co\.uk [NC]
RewriteRule ^(.*)$ https://info.new.com/blog/$1 [L,R=301,NC]

这里https://info.oldsite.co.uk/dsadasdsad会变成https://info.new.com.co.uk/%60https://info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/blog/fsdfdsfsd%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60
AND https://info.oldsite.co.uk/blog/dsadasdsad将转到https://info.new.com.com//blog/dsadasdsad(几乎可以正常工作,但此处有双斜杠“//”)

au9on6nz

au9on6nz1#

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^info\.oldsite\.co\.uk [NC]
RewriteRule ^(.*)$ https://info.new.com%1/$1 [L,R=301,NC]

因此,info.oldsite.co.uk/blog/xyzxyz会变成info.new.com/blog/xyzxyz

相关问题