【问题标题】:Redirect whole domain重定向整个域
【发布时间】:2012-10-26 16:08:48
【问题描述】:

是否可以将整个域重定向到另一个域?

我希望它以这种方式重定向:

domain.com/something --> www.domain.eu/something
sub.domain.com/folder/file.type --> sub.domain.eu/folder/file.type
super.mega.sub.domain.com --> super.mega.sub.domain.eu

(对于任何子域和 /. 之后的任何内容)

我只能访问 com 域。

到目前为止,我已经为 .htaccess 文件发明了这段代码:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule (.*)$ http://www.domain.eu/$1 [R=permanent,L]

但它的工作原理是:

sub.domain.com/something --> www.domain.eu/sub/something

所以这是错误的。 请问有什么帮助吗? 非常感谢。

【问题讨论】:

  • 我猜你可能会使用另一个域作为别名

标签: .htaccess redirect dns subdomain


【解决方案1】:

我通常只是创建一个 index.html 文件并使用元标记重定向它:

<meta http-equiv="refresh" content="0;URL=http://www.newdomain.ext">
<meta http-equiv="refresh" content="0;URL=http://subdomain.newdomain.ext">

【讨论】:

    【解决方案2】:

    好的,我假设您想将整个域重定向到另一个页面,而不仅仅是一个页面..

    所以只需在你的 htaccess 文件中写下以下几行

    重写引擎开启

    RewriteCond %{HTTP_HOST} ^yourolddomain.com$ [OR]

    RewriteCond %{HTTP_HOST} ^www.yourolddomain.com$

    重写规则 (.*)$http://www.yournewdomain.com/$1 [R=301,L]

    【讨论】:

      【解决方案3】:

      试试这个,而不是你拥有的:

      RewriteEngine On
      
      # for main domain
      RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
      RewriteRule ^(.*)$ http://www.domain.eu/$1 [L,R=301]
      
      # for all subdomains
      RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
      RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
      RewriteRule ^(.*)$ http://%1.domain.eu/$1 [L,R=301]
      

      【讨论】:

      • 感谢您的回复,但我注意到 Chrome 将 sub.domain.com 重定向到 sub.domain.eu/sub
      猜你喜欢
      • 1970-01-01
      • 2013-06-07
      • 2015-12-04
      • 1970-01-01
      • 2021-09-07
      • 2012-12-09
      • 2017-10-18
      • 1970-01-01
      • 2021-06-07
      相关资源
      最近更新 更多