30

在互联网上查找了大约一个小时后,我没有找到我的问题的答案。所以我用错误的关键字搜索,或者我想要的东西是不可能的。

我想要什么:
我有多个具有不同扩展名的域,例如:

  • 我的域名.be
  • 我的域名.nl

现在我想要的是 mydomain.be 被重定向到 mydomain.nl。我在互联网上找到的解决方案如下所示,需要.htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.be$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.be$
RewriteRule (.*)$ http://www.mydomain.nl/$1 [R=301,L]

使用此代码,当您键入 mydomain.be 时,您将被重定向到 mydomain.nl。但地址栏中的 URL 也更改为 mydomain.nl。我想要的是将 URL 保留在地址栏中 mydomain.be 中。

所以,mydomain.be:

  • 保留网址
  • 显示 mydomain.nl 的内容

如何?

4

2 回答 2

22

It is possible to get it done via mod_rewrite but make sure mod_proxy is enabled in your Apache's httpd.conf. Once that is done enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.be$ [NC]
RewriteRule ^ http://www.mydomain.nl%{REQUEST_URI} [L,NE,P]

Take note of flag P which is used for handling the proxy request.

Read more about flag: P in mod_rewrite

于 2013-04-15T09:01:02.320 回答
4

另一种无需麻烦的选择.htaccess是将两个域都指向同一个文档根目录或将一个域设置为另一个域的别名,具体取决于您如何配置 Apache。然而,这也有缺点:

  • 如果您的内容管理系统使用绝对 URL,则单击链接上的 mydomain.nl 的用户将被定向到 mydomain.be 域(例如,WordPress 就是这样做的)。
  • 搜索引擎通过将您放在搜索结果的下方来惩罚这种行为。至少谷歌有,他们有一篇关于重复内容的有趣博客文章。不确定竞争对手。

一个示例 apache 配置可能是:

<VirtualHost *:80>
    ServerName mydomain.nl
    ServerAlias mydomain.be

    DocumentRoot /var/www/mydomain.nl/htdocs
</VirtualHost>
于 2013-04-15T09:08:25.003 回答