我如何301重定向一个领域到另一个,如果第一次有一个文件夹路径文件夹、路径、有一个、重定向

2023-09-02 00:46:43 作者:嗜你如命

我要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

 
精彩推荐
图片推荐