.htaccess 重定向整个域

.htaccess 重定向整个域,.htaccess,redirect,dns,subdomain,.htaccess,Redirect,Dns,Subdomain,是否可以将整个域重定向到另一个域 我希望它以这种方式重定向: 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域 到目前为止,我为.

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

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

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
所以这是错误的。 需要帮忙吗?
非常感谢。

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

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]

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

因此,只需在htaccess文件中写入以下行

重新启动发动机

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

重写cond%{HTTP_HOST}^www.yourlddomain.com$

重写规则(.*)$$1[R=301,L]


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

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


我想你可能会使用另一个域名作为别名,而不是别名谢谢你的回复,但我注意到Chrome将sub.domain.com重定向到sub.domain.eu/sub