收藏 分享(赏)

APACHE通过URL重写伪静态.doc

上传人:hwpkd79526 文档编号:7218408 上传时间:2019-05-10 格式:DOC 页数:5 大小:33KB
下载 相关 举报
APACHE通过URL重写伪静态.doc_第1页
第1页 / 共5页
APACHE通过URL重写伪静态.doc_第2页
第2页 / 共5页
APACHE通过URL重写伪静态.doc_第3页
第3页 / 共5页
APACHE通过URL重写伪静态.doc_第4页
第4页 / 共5页
APACHE通过URL重写伪静态.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、APACHE 通过 URL 重写伪静态一Apache 设置 独立主机用户Apache 基本配置:首先确定您使用的 Apache 版本,及是否加载了 mod_Rewrite 模块。Apache 1.x 的用户请检查 conf/httpd.conf 中是否存在如下两段代码:LoadModule Rewrite_module libexec/mod_Rewrite.soAddModule mod_Rewrite.cApache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码:LoadModule Rewrite_module modules/mod_Rewrite.so

2、如果没有安装 mod_Rewrite,您可以重新编译 Apache,并在原有 configure 的内容中加入 -enable-Rewrite=shared注:如果前面有#,将其去掉。方法一:通过配置 Apache 配置文件 httpd.conf 实现 URL 重写在配置文件(通常就是 conf/httpd.conf)中加入如下代码。RewriteEngine OnRewriteRule(.*)/archiver/(fid|tid)-w-+.html)$ $1/archiver/index.php?$2RewriteRule(.*)/forum-(0-9+)-(0-9+).html$ $1/f

3、orumdisplay.php?fid=$2&page=$3RewriteRule(.*)/thread-(0-9+)-(0-9+)-(0-9+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3RewriteRule (.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3RewriteRule (.*)/tag-(.+).html$ $1/tag.php?name=$2注:此时请务必注意,如果网站使用通过虚拟主机来定义,请务必加到虚拟主机配置,即 中去,如果加在虚拟主机配置外部

4、将可能无法使用,改好后将 Apache 重启。方法二:通过在根目录中的跨越配置文件.htaccess 实现 URL 重写1.配置 apache 支持对 .htaccess 文件的解析查找:Options FollowSymLinksAllowOverride None修改为:Options FollowSymLinksAllowOverride Allman 对 AllowOverride 的解释:AllowOverride controls what directives may be placed in .htaccess files.It can be “All“, “None“, or

5、 any combination of the keywords:Options FileInfo AuthConfig Limit就是说,将 None 改为 All,.htaccess 文件才能被支持!2. 创建.htaccess 文件 Win32 系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 D 技术支持栏目中下载此文件。(附件中可下载)3. 编辑.htaccess 文件# 将 RewriteEngine 模式打开RewriteEngine On# .htaccess 文件路径,如果在系统跟目录则为 RewriteBase /,如果在根目录下的其他文件

6、夹,如在根目录下的 test 文件夹,则为 RewriteBase /test,此处将.htaccess 放在根目录下。RewriteBase /discuz# Rewrite 系统规则请勿修改RewriteRule archiver/(fid|tid)-w-+.html)$ archiver/index.php?$1RewriteRuleforum-(0-9+)-(0-9+).html$ forumdisplay.php?fid=$1&page=$2RewriteRulethread-(0-9+)-(0-9+)-(0-9+).html$ viewthread.php?tid=$1&extra

7、=page%3D$3&page=$2RewriteRule space-(username|uid)-(.+).html$ space.php?$1=$2RewriteRule tag-(.+).html$ tag.php?name=$1租用空间用户(多是虚拟主机用户)1. 首先咨询您的空间服务商,空间是否支持 Rewrite 以及是否支持对站点目录中 .htaccess 的文件解析,否则即便按照下面的方法设置好了,也无法使用。2. 创建.htaccess 文件 Win32 系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 D 技术支持栏目中下载此文件。3.

8、编辑.htaccess 文件# 将 RewriteEngine 模式打开RewriteEngine On# .htaccess 文件路径,如果在系统跟目录则为 RewriteBase /,如果在根目录下的其他文件夹,如在根目录下的 test 文件夹,则为 RewriteBase /test,此处将.htaccess 放在根目录下。RewriteBase /discuz# Rewrite 系统规则请勿修改RewriteRule archiver/(fid|tid)-w-+.html)$ archiver/index.php?$1RewriteRuleforum-(0-9+)-(0-9+).htm

9、l$ forumdisplay.php?fid=$1&page=$2RewriteRulethread-(0-9+)-(0-9+)-(0-9+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2RewriteRule space-(username|uid)-(.+).html$ space.php?$1=$2RewriteRule tag-(.+).html$ tag.php?name=$1二Rewrite 规则上面无论是在 apache 中设置的:RewriteEngine OnRewriteRule(.*)/archiver/(fid

10、|tid)-w-+.html)$ $1/archiver/index.php?$2RewriteRule(.*)/forum-(0-9+)-(0-9+).html$ $1/forumdisplay.php?fid=$2&page=$3RewriteRule(.*)/thread-(0-9+)-(0-9+)-(0-9+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3RewriteRule (.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3RewriteRule (.*)/t

11、ag-(.+).html$ $1/tag.php?name=$2还在是文件.htaccess 中添加的:# 将 RewriteEngine 模式打开RewriteEngine On# .htaccess 文件路径,如果在系统跟目录则为 RewriteBase /,如果在根目录下的其他文件夹,如在根目录下的 test 文件夹,则为 RewriteBase /test,此处将.htaccess 放在根目录下。RewriteBase /discuz# Rewrite 系统规则请勿修改RewriteRule archiver/(fid|tid)-w-+.html)$ archiver/index.ph

12、p?$1RewriteRuleforum-(0-9+)-(0-9+).html$ forumdisplay.php?fid=$1&page=$2RewriteRulethread-(0-9+)-(0-9+)-(0-9+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2RewriteRule space-(username|uid)-(.+).html$ space.php?$1=$2RewriteRule tag-(.+).html$ tag.php?name=$1其中都指明了 URL 重写规则。请看:RewriteRuleforum-(0-9+)-(0-9+).html$ forumdisplay.php?fid=$1&page=$2这句说明了 URL 为 forumdisplay.php?fid=$1&page=$2 可以写成 forum-(0-9+)-(0-9+).html 这种模式。如:访问 http:/localhost/ forumdisplay.php?fid=1&page=2 与访问http:/localhost/ forum-1-2.html 的效果是一样的!注:这些规则是可以自己写正则表达式随意更改的。根据自己需要的格式。来定制 URL 重写规则。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报