重定向到其他域但保留键入的域 [英] Redirect to other domain but keep typed domain

查看:27
本文介绍了重定向到其他域但保留键入的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After looking on the internet for about an hour, I didn't find the answer to my question. So I'm searching with the wrong keywords or what I want is not possible.

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

What I want:
I have multiple domains with different extensions, for example:

  • mydomain.be
  • mydomain.nl

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

Now what I want is that the mydomain.be is redirected to mydomain.nl. The solution for this I have found on the internet and shown below, with the need of .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 中.

With this code, when you type mydomain.be you will be redirect to mydomain.nl. But also the URL in the addressbar is changed to mydomain.nl. What I want is to keep the URL in the addressbar mydomain.be.

所以,mydomain.be:

So, mydomain.be:

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

怎么做?

推荐答案

可以通过 mod_rewrite 完成,但要确保在 Apache 的 httpd.conf 中启用了 mod_proxy.完成后,通过 httpd.conf 启用 mod_rewrite 和 .htaccess,然后将此代码放在 DOCUMENT_ROOT 目录下的 .htaccess 中:

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]

注意用于处理代理请求的标志P.

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

详细了解标志:mod_rewrite 中的 P

这篇关于重定向到其他域但保留键入的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆