.htaccess 如何使用一个htaccess文件从多个域到一个新域的新url

sh7euo9m  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(153)

我试图只在一个Apache服务器上使用一个HTAccess文件。我有多个域名指向HTAccess文件所在服务器的IP地址。
我想做的是使用一个htaccess文件将不同域中的不同页面URL重定向到新域中的新URL。
这不起作用,但这就是我要说的,希望能进一步解释:

RewriteEngine On
Redirect 301 old-domain1.com/url.html https://newsite.com/url-from-domain1.html
Redirect 301 old-domain2.com/url.html https://newsite.com/url-from-domain2.html
Redirect 301 old-domain3.com/url.html https://newsite.com/url-from-domain3.html
w8rqjzmb

w8rqjzmb1#

这就是我要找的,效果和预期的一样。

RewriteEngine On
RewriteBase /

# Redirect old-domain1.com/url.html to https://new-domain1.com/new-url.html
RewriteCond %{HTTP_HOST} ^old-domain1\.com$ [NC]
RewriteRule ^url\.html$ https://new-domain1.com/new-url.html [R=301,L]

# Redirect old-domain2.com/old-url.html to https://new-domain2.com/new-url.html
RewriteCond %{HTTP_HOST} ^old-domain2\.com$ [NC]
RewriteRule ^old-url\.html$ https://new-domain2.com/new-url.html [R=301,L]

# Redirect old-domain3.com/another-url.html to https://new-domain3.com/different-url.html
RewriteCond %{HTTP_HOST} ^old-domain3\.com$ [NC]
RewriteRule ^another-url\.html$ https://new-domain3.com/different-url.html [R=301,L]

相关问题