指引网

当前位置: 主页 > 服务器 > Apache >

apache 伪静态配置方法

来源:网络 作者:佚名 点击: 时间:2017-06-18 20:42
[摘要] 

apache 伪静态配置方法

Apache伪静态html(URL Rewrite)设置法

phpma一 打开 Apache 的配置文件 httpd.conf 。

phpma二 将#LoadModule rewrite_module modules/mod_rewrite前面的#去掉

phpma三 在 httpd.conf中添加:

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+.html
    RewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+).html$ $1.php?

__is_apache_rewrite=1&__rewrite_arg=$2
</IfModule>

 

<ifmodule mod_rewrite.c>
 RewriteEngine On
 RewriteRule /news/top2007,(d+).html$   /news/readmore.php?id=$1
</ifmodule>
四 保存httpd.conf并重启apache。


Apache Web Server(独立主机用户)

首先确定您使用的 Apache 版本,及是否加载了 mod_rewrite 模块。

Apache 1.x 的用户请检查 conf/httpd.conf 中是否存在如下两段代码:

LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c

Apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码:

LoadModule rewrite_module modules/mod_rewrite.so

如果存在,那么在配置文件(通常就是 conf/httpd.conf)中加入如下代码。此时请务必

注意,如果网站使用通过虚拟主机来定义,请务必加到虚拟主机配置,即 <VirtualHost>

中去,如果加在虚拟主机配置外部将可能无法使用。改好后然后将 Apache 重启。

<IfModule mod_rewrite.c>
       RewriteEngine On
RewriteRule ^(.*)/ivideo(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-

([0-9]+))?.html$ $1/ivideo.php?tv=$3&ti=$5&tc=$7&page=$9
RewriteRule ^(.*)/ispecial(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-

([0-9]+))?.html$ $1/ispecial.php?tv=$3&ti=$5&tc=$7&page=$9
RewriteRule ^(.*)/icategory.html$ $1/icategory.php
RewriteRule ^(.*)/category-cid-([0-9]+)(-tag-([^-]*))?(-timelimit-([0-9]+))?(-

orderlimit-([0-9]+))?(-page-([0-9]+))?.html$ $1/category.php?

cid=$2&tag=$4&timelimit=$6&orderlimit=$8&page=$10
RewriteRule ^(.*)/vspace-(mid|username)-(.+).html$ $1/vspace.php?$2=$3
RewriteRule ^(.*)/video-(vid|ivid)-(.+).html$ $1/video.php?$2=$3
RewriteRule ^(.*)/special-spid-([0-9]+).html$ $1/special.php?spid=$2
</IfModule>
如果没有安装 mod_rewrite,您可以重新编译 Apache,并在原有 configure 的内容中加

入 --enable-rewrite=shared,然后再在 Apache 配置文件中加入上述代码即可。

Apache Web Server(虚拟主机用户)

在开始以下设置之前,请首先咨询您的空间服务商,空间是否支持 Rewrite 以及是否支持

对站点目录中 .htaccess 的文件解析,否则即便按照下面的方法设置好了,也无法使用。

检查播客所在目录中是否存在 .htaccess 文件,如果不存在,请手工建立此文件。Win32

系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在

discuz.net 技术支持栏目中下载此文件。编辑并修改 .htaccess 文件,添加以下内容 #

将 RewriteEngine 模式打开
RewriteEngine On
# 修改以下语句中的 /supev 为你的播客目录地址,如果程序放在根目录中,请将 /supev

修改为 /
RewriteBase /supev
# Rewrite 系统规则请勿修改 RewriteRule

RewriteRule ^ivideo(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-([0-9]

+))?.html$ ivideo.php?tv=$2&ti=$4&tc=$6&page=$8
RewriteRule ^ispecial(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-([0-

9]+))?.html$ ispecial.php?tv=$2&ti=$4&tc=$6&page=$8
RewriteRule ^icategory.html$ icategory.php
RewriteRule ^category-cid-([0-9]+)(-tag-([^-]*))?(-timelimit-([0-9]+))?(-

orderlimit-([0-9]+))?(-page-([0-9]+))?.html$ category.php?

cid=$1&tag=$3&timelimit=$5&orderlimit=$7&page=$9
RewriteRule ^vspace-(mid|username)-(.+).html$ vspace.php?$1=$2
RewriteRule ^video-(vid|ivid)-(.+).html$ video.php?$1=$2
RewriteRule ^special-spid-([0-9]+).html$ special.php?spid=$1


<VirtualHost *:80>
DocumentRoot /home/www_php168
ServerName www.111cn.net
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/list-([0-9]+)-([0-9]+).htm$ $1/list.php?fid=$2&page=$3
RewriteRule ^(.*)/bencandy-([0-9]+)-([0-9]+)-([0-9]+).htm$ $1/bencandy.php?

fid=$2&id=$3&page=$4
</IfModule>
</VirtualHost>

------分隔线----------------------------