简体   繁体   English

php htaccess重定向

[英]php htaccess redirect

i have a site in php. 我在php中有一个网站。 now i want to redirect my older site url to new url. 现在我想将我的旧站点URL重定向到新URL。

whenever user enter my old site url in address bar using browser url must be redirect to my new url. 每当用户使用浏览器网址在地址栏中输入我的旧网站网址时,都必须重定向到我的新网址。

How can i do this using .htaccess file. 我如何使用.htaccess文件执行此操作。

Thanks in advance. 提前致谢。

If you have a page by page mapping you can do it like this: 如果有逐页映射,则可以这样进行:

RewriteEngine on
RewriteRule index.php http://www.example.com/index.asp [R=301]
RewriteRule prods.html http://www.example.com/products.xhtml [R=301]

The first part ex, index.php is the local name index.asp is the remote name, [R=301] Means you are using a 301 as prescribed in RFC2616 meaning the file has moved permanently. 第一部分,例如index.php是本地名称index.asp是远程名称, [R=301]您使用的是RFC2616中规定301,表示文件已永久移动。

If all the files map perfectly in some way to another server you can do it like this: 如果所有文件都以某种方式完美地映射到另一台服务器,则可以执行以下操作:

RewriteEngine on
RewriteRule (.*) http://www.example.com/$1 [R=301]

Here you capture all requests and say that the file can now be found on example.com whatever it is called. 在这里,您捕获了所有请求,并说该文件现在可以在example.com上找到,不管它叫什么。

Best of luck. 祝你好运。

or edit your index.php at your old site 或在旧站点上编辑index.php

<php  
header('Location: http://newsite.com');
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM