【问题标题】:Change the url of the web browser [closed]更改网络浏览器的网址 [关闭]
【发布时间】:2011-11-11 06:50:38
【问题描述】:
如果有人输入
www.xxx.com/website
那么它应该变成
www.xxx.com/new.php?id=website
按回车
【问题讨论】:
标签:
php
apache
url
browser
【解决方案1】:
查看 apache 的 mod_alias:http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectpermanent
如果你很懒,你可以在 /website/ 中添加一个 index.php 并在其中添加:
<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.xxx.com/new.php?id=website" );
?>
请注意,这两个都发送 HTTP 301 Moved Permanently 标头,因此重定向将存储在用户缓存中直到它清除,因此即使您出于任何原因删除重定向,之前访问过 /website/ 的用户也会仍然被重定向。
【解决方案3】:
你可以通过 PHP(上面提到的)来实现,也可以通过 .htaccess 来实现:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^website(/)?$ www.xxx.com/new.php?id=website [R=301,L]
这意味着如果用户访问www.xxx.com/website,他将被重定向到www.xxx.com/new.php?id=website。
【解决方案4】:
在 PHP 中你可以这样做:
$nav = $_SERVER["ORIG_PATH_INFO"]; // get path.
$v = explode("/", $nav);
header('Location: new.php?id=' . $v[0]);
尚未测试此代码,因此可能存在一些错误,但类似的东西会起作用。