Subscribe:Posts Comments

You Are Here: Home » 网络班 » 无需.htaccess也能做301指向

很多时候我们因为很多原因需要做301转向,就好比我做的一个游戏论坛。有两个程序,一个/bbs,一个/home,而根目录又暂时用不到,怎么办呢?.htaccess固然很不错,但.htaccess越多服务器负担越重,命令越多也同样如此。

谢谢牢骚网的朋友给我的帮助,教会我了使用index.php来做301转向。

建立一个index.php文件,输入以下代码:

<?php
function PMA_getenv($var_name) {
if (isset($_SERVER[$var_name])) {
return $_SERVER[$var_name];
} elseif (isset($_ENV[$var_name])) {
return $_ENV[$var_name];
} elseif (getenv($var_name)) {
return getenv($var_name);
} elseif (function_exists(‘apache_getenv’)
&& apache_getenv($var_name, true)) {
return apache_getenv($var_name, true);
}
return ”;
}
if (empty($HTTP_HOST)) {
if (PMA_getenv(‘HTTP_HOST’)) {
$HTTP_HOST = PMA_getenv(‘HTTP_HOST’);
} else {
$HTTP_HOST = ”;
}
}
$domain = htmlspecialchars($HTTP_HOST);

if($domain==’www.1.com‘){
header(‘Location: bbs/index.php’);
}elseif($domain==’www.2.com‘){
header(‘Location: bbs/index.php’);
}elseif($domain==’www.3.com/home‘){
header(‘Location: home/index.php’);
}elseif($domain==’www.4.org/home‘){
header(‘Location: home/index.php’);
}else{}
?>

根据自己的需要替换红色部分的网址,”Location:”为指向的目录。

注:此方法只能用在同一目录下,如果想转移到其他网站,需要做域名指向。

Tags: , ,

2 Comments

  1. 浩然 says:

    这个是智能指向的吗?就是自动把全站某个定制的域名字母段转化成想要的~

Leave a Reply

© 1997 - 2010 寂静街 · Powered by 女神工作室.