apache泛域名配置+泛域名指向处理文件

泛域名解析配置与PHP实现
本文介绍如何配置Apache服务器以支持泛域名解析,并通过PHP脚本实现对不同子域名的个性化跳转处理。示例中包括了针对特定二级域名的直接跳转以及通过数据库查询来确定跳转目标的方法。

http://wesoho.blog.51cto.com/715082/224158



# 泛域名解析
<VirtualHost 你的ip:80>
    ServerName *.dswind.com
    ServerAlias *.dswind.com
    DocumentRoot "x:/Fanyuming"
  <Directory "x:/Fanyuming">
 Options FollowSymLinks
 AllowOverride All
 Order allow,deny
 Allow from all
    </Directory>
</VirtualHost>
 
x:/Fanyuming 放一个文件index.php 负责解释泛域名指向
 
<?php
$url_this=$_SERVER ['HTTP_HOST'];
$url_this=str_replace ("www.", "", $url_this);
$url_this=str_replace (".dswind.com", "", $url_this);
$url_this=str_replace ("'", "", $url_this);
$url_this=str_replace ("@", "", $url_this);
$url_this=str_replace ("=", "", $url_this);
$url_this=str_replace (";", "", $url_this);
//固定二级域名优先解析
if($url_this=='2008')
{
header("location:"." http://www.dswind.com/zhuanti/ds13/ ");
}
if($url_this=='2009')
{
header("location:"." http://www.dswind.com/aboutus/yantaohui/");
}
if($url_this=='pku')
{
header("location:"." http://www.dswind.com/zhuanti/yantao/");
}
$dbh = mysql_connect('localhost','用户名','密码');
mysql_select_db('数据库名');
$query = "从数据库查询记录";
$res = mysql_query($query, $dbh);
$err = mysql_error();
if($err){
echo "发生错误,请通知站长";
exit;
}
$row = mysql_fetch_row($res);
if(empty($row[0]))
{
echo "<script>alert('该网址不存在');document.location='http://www.dswind.com'</script>";
exit;
}
else
{ header("location:"." http://www.dswind.com/member/index.php?uid=".$row[0]); }
?>
<html>
<head>
</head>
<body>
 正在进入<a href=http://dswind.com target=_blank>中华直销网</a>直销圈....
</body>
</html>
 

本文出自 “扬帆技术博客” 博客,请务必保留此出处http://wesoho.blog.51cto.com/715082/224158







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值