21
十二

无需.htaccess也能做301指向

   Posted by: 等待一生   in 网络班

很多时候我们因为很多原因需要做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:"为指向的目录。

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

Related posts:

  1. UCH1.5正式版点击首页回到index.php页面解决方案
  2. Discuz!、UC Home 在Nginx下的静态规则
  3. Hostmonster Addon Domain
  4. 利用Wordpress自定义域优化SEO
  5. 使用mod_cband控制Apache2带宽和流量
  6. Godaddy linux使用CURL连接
  7. 自动备份mysql数据库并发送到Email
  8. Lunarpages域名转移至Godaddy
  9. 很不错的MV,动漫歌曲,真人演绎 - -
  10. Godaddy 虚拟主机安装Zend 3.3升级php5.ini

Tags: , ,

发表评论之余,您还可以到寂静街论坛与我们一起讨论您的观点哦。

This entry was posted on 星期天, 十二月 21st, 2008 at 12:54 上午 and is filed under 网络班. You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.

One comment

 1 

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

[回复]

等待一生 回复:

不能- -

[回复]

一月 26th, 2010 at 1:09 下午

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment