将特定页面重定向到另一个域 [英] Redirecting a specific page to another domain
问题描述
我最近在另一个域上创建了一个新站点.我需要将旧域的index.html
重定向到新域的索引.
I recently created a new site on a different domain. I need to redirect the index.html
of the old domain to the index of the new domain.
通常这不是问题,但是旧域是服务器的根域,新域是附加组件.因此,以下行将导致重定向循环,因为它将a.com/index.html
和b.com/index.html
重定向到b.com/index.html
.
Usually this would not be a problem, but the old domain is the root domain of the server, the new one is an add on. So the following line would cause a redirect loop because it redirects a.com/index.html
and b.com/index.html
to b.com/index.html
.
Redirect 301 /index.html http://b.com/
有没有办法做这样的事情?
Is there a way of doing something like this?
Redirect 301 http://a.com/index.html http://b.com/
TL; DR 如何将一个域上的index.html
重定向到另一个域而不会级联并引起循环,因为另一个域是一个附加域(即,位于该域下的同一文件夹中)相同.htaccess
的定律).
TL;DR How can I redirect index.html
on one domain to another domain without it cascading and causing a loop because the other domain is a add on domain (i.e. in the same folder therefor under the law of the same .htaccess
).
推荐答案
您可以使用以下代码尝试mod_rewrite以获得更大的灵活性:
You can try mod_rewrite for more flexibility with the code like this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for HTTP
RewriteCond %{HTTP_HOST} ^a\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(index\.html)$ http://b.com/$1 [R=301,L,NC]
# for HTTPS
RewriteCond %{HTTP_HOST} ^a\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(index\.html)$ https://b.com/$1 [R=301,L,NC]
这篇关于将特定页面重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!