合肥网站建设
文章阅读
网建技巧
优化技巧
网建问题
谨宸新闻
行业新闻

首页 > 合肥网站建设 > 正文

如何利用apache重写静态页面

发布时间:2011/05/05字体:
摘要:如何利用apache重写静态页面,apache重写静态页面,如何开启apache重写,apache重写规,本技巧重点介绍在apache中如何开启apache重写规则,并实例讲解了apache重写静态页面案例。具体方法如下:apache配置文件httpd.conf中加载:mod_rewrit

本技巧重点介绍在apache中如何开启apache重写规则,并实例讲解了apache重写静态页面案例

 具体方法如下:
apache配置文件httpd.conf中加载:LoadModule rewrite_module modules/mod_rewrite.so

两种方法重写
第一种:
   
        RewriteEngine On
            RewriteRule ^\/content/(.*)_(.*)htm$ /test.php?q=$1&a=$2
   

介绍:这种方法,比如链接文件:test.php,这样链接的页面实际请求的页面是:test.php?q=2303&a=ok.前面的content是伪装的

例子:
a.html :
    test.php
test.php :
            echo $_GET["q"];//结果是2303
        echo $_GET["a"];//结果是ok.(有一个.)
    ?>



第二种:
#这里的content就是要伪装的文件夹名称
    ForceType application/x-httpd-php


介绍:这种方法实际意义上说不是伪装content文件夹,而是让服务器解释content文件,没有拓展名的content文件.

例子:
a.html :
    test.php
有一个content的文件,没有拓展名
content :
                $fields = explode('/', $_SERVER['REQUEST_URI']);
            $id_pos = array_search('content', $fields);
            if( $id_pos !== false ){
                $c_id = $fields[ $id_pos + 1 ];
                $a_id = $fields[ $id_pos + 2 ];
            }
            if( $a_id ){
                $_GET['aid'] = $a_id;
                $_GET['cid'] = $c_id;
                require_once('showarticle.php');
            }
    ?>
test.php :
            echo $_GET['aid'];//结果是445
        echo $_GET['cid'];//结果是0
    ?>
   


下面是一些值得学习的apache重写规则:
RewriteEngine On
RewriteRule index.html$ index.php
RewriteRule ^([a-zA-Z]+)/$ index.php?en=$1
RewriteRule ^([a-zA-Z]+)$ index.php?en=$1
RewriteRule ^([0-9]+)\.html$ view.php?id=$1
RewriteRule ^([0-9]+)_([a-zA-Z0-9]+)\.html$ view.php?id=$1&user=$2

    RewriteRule ^/([0-9]+)\.htm$ /test.php?id=$1
    RewriteRule ^/newsview-([0-9]+)_([0-9]+)_([0-9]+)_([a-z]+)\.htm$ /test.php?type=$1&id=$2&page=$3&user=$4
    RewriteRule ^/test\.htm$ /test.php
    #RewriteRule ^/(.*)\.htm$ /test.php?add=$1
    RewriteRule new.html$ a.php
    RewriteRule ^/content/([a-z]+)_([0-9]+)\.html$ /a.php?who=$1&$page=$2
    RewriteRule ^/([0-9]?).html$ /a.php?who=$1


RewriteEngine On
RewriteRule index.html$ index.php
RewriteRule ^([0-9]+)\.html$ read.php?id=$1
RewriteRule ^([0-9]+)_([0-9]+)\.html$ read.php?id=$1&p=$2

RewriteRule industry.html$ info.php?type=1
RewriteRule design.html$ info.php?type=2
RewriteRule interview.html$ info.php?type=3
RewriteRule exhibition.html$ info.php?type=4
RewriteRule home.html$ info.php?type=5
RewriteRule help.html$ info.php?type=6
RewriteRule bbs.html$ info.php?type=7
RewriteRule 99cad.html$ info.php?type=8
RewriteRule recruitment.html$ info.php?type=9


RewriteRule index.html$ index.php
RewriteRule ^([0-9]+)\.html$ view.php?id=$1

RewriteRule index.html$ index.php
RewriteRule ^([0-9]+)\.html$ read.php?id=$1
RewriteRule ^([0-9]+)_([0-9]+)\.html$ read.php?id=$1&p=$2

RewriteRule industry.html$ info.php?type=1
RewriteRule design.html$ info.php?type=2
RewriteRule interview.html$ info.php?type=3
RewriteRule exhibition.html$ info.php?type=4
RewriteRule home.html$ info.php?type=5
RewriteRule help.html$ info.php?type=6
RewriteRule bbs.html$ info.php?type=7
RewriteRule d.html$ info.php?type=8
RewriteRule recruitment.html$ info.php?type=9
本文标题:如何利用apache重写静态页面
本文网址:http://www.055178.com/wangjianjiqiao/48.html
原创网址:合肥网络公司<谨宸科技> 版权所有,转载请注明出处,并以链接形式链接网址:www.055178.com
文章标签:apache静态页面
 上一篇:如何做好网站链接
 下一篇:贡献05年学习javascript和div+css时候总结的一些小技巧