windows2003+apache实现url重定向

xiaoxiao2021-02-27  234

因为网站备案的原因,域名服务商关闭了域名url的重定向服务,所以需要自己实现url重定向,总结方法如下:

 

*************************************************************************************************方法1:增加一个view.php导航页,然后修改httpd.conf的重定向配置*************************************************************************************************

把下面两句放在httpd.conf的最后:RewriteEngine OnRewriteRule ^/(\d+)\.html$ /test/view\.php\?id=$1

建立导航view.php内容如下<?

     $a=$_GET["id"];     echo $a;

?>

 

*************************************************************************************************方法2:修改httpd.conf,建立多个虚拟主机*************************************************************************************************

<VirtualHost 192.168.0.8>    ServerAdmin webmaster@mail.example.tpc.edu.tw    DocumentRoot c:/AppServ/www/    ServerName www.example.tpc.edu.tw</VirtualHost>

這裡的 DocumentRoot 要指向 httpd.conf 中的設定DocumentRoot "/var/www/html"   (Linux 的預設值)DocumentRoot "c:/AppServ/www/" (AppServ 的預設值)你要設定哪一種要看你使用 Linux 或 AppServ 而定

<VirtualHost 192.168.0.8>    ServerAdmin am@mail.example.tpc.edu.tw" href="mailtoam@mail.example.tpc.edu.tw">sam@mail.example.tpc.edu.tw    DocumentRoot d:/home/sam                         (使用者要上傳網頁的目錄)    ServerName sam.example.tpc.edu.tw</VirtualHost>

<VirtualHost 192.168.0.8>    ServerAdmin eric@mail.example.tpc.edu.tw    DocumentRoot d:/home/eric                         (使用者要上傳網頁的目錄)    ServerName eric.example.tpc.edu.tw</VirtualHost>

<VirtualHost 192.168.0.8>    ServerAdmin avid@mail.example.tpc.edu.tw" href="mailtoavid@mail.example.tpc.edu.tw">david@mail.example.tpc.edu.tw    DocumentRoot d:/home/david                         (使用者要上傳網頁的目錄)    ServerName david.example.tpc.edu.tw</VirtualHost>

 

*************************************************************************************************方法3:导航程序直接实现*************************************************************************************************

建立index.php内容如下:

<?php

$dn=$_SERVER["SERVER_NAME"];$url=""; //转发地址$flag=0; //转发方式 0-直接重定向 1-frame隐藏switch($dn){   case "www.sosunbj.com":   case "sosunbj.com":   case "www.sosunbj.cn":   case "sosunbj.cn":   case "bbs.sosunbj.com":   case "bbs.sosunbj.cn":     $url="http://www.sosunbj.com/Discuz!_6.0.0_SC_UTF8/upload/";     $flag=0;     break;

   default:     $url="http://www.sosunbj.com/Discuz!_6.0.0_SC_UTF8/upload/";     $flag=0;     break;}

if($flag==0){   header("location:".$url);   exit(0);}//后面的是隐藏URL转发?>

<html>  <head>   <title>zhuzhu导航器</title>  </head>  <frameset framespacing="0" border="0" rows="0" frameborder="0">  <frame name="main" src="<?phpecho $url;?>" scrolling="auto">  </frameset>  </html>

转载请注明原文地址: https://www.6miu.com/read-10448.html

最新回复(0)