【发布时间】:2010-09-14 06:15:59
【问题描述】:
我有一个 php 网站。 现在我想将我的旧网站网址重定向到新网址。
每当用户使用浏览器 url 在地址栏中输入我的旧网站 url 时,都必须重定向到我的新 url。
我如何使用 .htaccess 文件来做到这一点。
提前致谢。
【问题讨论】:
-
这必须标记为“apache”。
标签: php apache .htaccess redirect using
我有一个 php 网站。 现在我想将我的旧网站网址重定向到新网址。
每当用户使用浏览器 url 在地址栏中输入我的旧网站 url 时,都必须重定向到我的新 url。
我如何使用 .htaccess 文件来做到这一点。
提前致谢。
【问题讨论】:
标签: php apache .htaccess redirect using
如果您有逐页映射,您可以这样做:
RewriteEngine on
RewriteRule index.php http://www.example.com/index.asp [R=301]
RewriteRule prods.html http://www.example.com/products.xhtml [R=301]
第一部分 ex,index.php 是本地名称 index.asp 是远程名称,[R=301] 表示您正在使用 301 as prescribed in RFC2616 表示文件已永久移动。
如果所有文件都以某种方式完美映射到另一台服务器,您可以这样做:
RewriteEngine on
RewriteRule (.*) http://www.example.com/$1 [R=301]
在这里您捕获所有请求并说现在可以在 example.com 上找到该文件,无论它被称为什么。
祝你好运。
【讨论】:
或在旧站点编辑 index.php
<php
header('Location: http://newsite.com');
?>
【讨论】:
【讨论】: