How do I 301 redirect one domain to the other if the first has a folder path

人盡茶涼 提交于 2019-12-22 17:52:59

问题


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

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


回答1:


Try this rule:

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

Where old.example.com is the old host name and new.example.com the new.




回答2:


<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>

This should also work for you.



来源:https://stackoverflow.com/questions/881640/how-do-i-301-redirect-one-domain-to-the-other-if-the-first-has-a-folder-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!