我如何301重定向一个领域到另一个,如果第一次有一个文件夹路径 [英] How do I 301 redirect one domain to the other if the first has a folder path

查看:150
本文介绍了我如何301重定向一个领域到另一个,如果第一次有一个文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要301重定向:www.olddomain.com到newdomain.com的根源,但我想它不管文件夹路径是对旧域什么工作。例如:下面的应该都重定向到newdomain.com

I want to 301 redirect from: www.olddomain.com to the root of newdomain.com but I want it to work no matter what the folder path is on the old domain. eg: the following should all redirect to the root of newdomain.com

www.olddomain.com
olddomain.com
www.olddomain.com/folder/file.php
olddomain.com/folder/file.php

我怎样才能做到这一点与现代重写的.htaccess文件?

How can I do that with Mod Rewrite in the .htaccess file?

推荐答案

试试这个规则:

RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$
RewriteRule ^ http://new.example.com/ [L,R=301]

其中, old.example.com 是旧的主机名和 new.example.com

这篇关于我如何301重定向一个领域到另一个,如果第一次有一个文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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