将页面重定向到不同域下的同一页面 [英] Redirecting a page to the same page under a different domain

查看:77
本文介绍了将页面重定向到不同域下的同一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改域名,并希望建立这样的结构:

I am changing domain names and want to set up a structure like so:

如果用户访问 www.olddomain.com/page >,他将被重定向到 www.newdomain.com/page 等。换句话说,仅域名的斜杠前部分会更改。我想对旧域下的所有页面执行此操作。

If a user accesses www.olddomain.com/page, he will be re-directed to www.newdomain.com/page, etc. In other words, only the pre-slash part of the domain would change. I want to do this for all pages under the old domain.

有人知道我该如何配置它?

Does anyone know how I can configure this?

推荐答案

可以在旧域的文档根中的htaccess文件中以多种方式执行此操作。如果旧域和新域位于不同的服务器上,或者至少位于不同的文档根目录下,则只需使用mod_alias的重定向即可:

Can do this a number of ways in the htaccess file in the document root of your old domain. If the old and new domains are on different servers, or at least different document roots, then you can simply use mod_alias' redirect:

Redirect 301 / http://www.newdomain.com/

如果您对共享有些困惑域之间的文件夹或它们位于相同的文档根目录中,则需要检查HTTP HOST字段并使用mod_rewrite:

If you have some confusion about sharing folders between the domains or they reside in the same document root, you'll need to check the HTTP HOST field and use mod_rewrite:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]

这篇关于将页面重定向到不同域下的同一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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