侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

apache中伪静态配置和使用(Apache虚拟主机下Discuz伪静态)

linux  /  管理员 发布于 7年前   320

一 打开 Apache 的配置文件 httpd.conf 。
二 将#LoadModule rewrite_module modules/mod_rewrite前面的#去掉
三 在 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>

四 要实现asp帖子URL到php帖子的映射,在 第三步的<IfModule mod_rewrite.c>和</IfModule>之间添加:
RewriteMap tolowercase int:tolower
RewriteCond %{QUERY_STRING} (?:boardid|page|id|replyid|star|skin)\=\d+ [NC]
RewriteRule ^(.*(?:index|dispbbs))\.asp$ $1.php?${tolowercase:%{QUERY_STRING}}&__is_apache_rewrite=1

五 保存httpd.conf并重启Apache。

六、mod_rewrite 简介
Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范。平时帮助我们实现伪静态,拟目录,域名跳转,防止盗链等等

七、mod_rewrite 规则的使用

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.php100.com [NC]
RewriteRule ^/(.*) http://www.php100.com/ [L]
--------
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]

八、mod_rewrite 规则修正符

1) R 强制外部重定向
2) F 禁用URL,返回403HTTP状态码。
3) G 强制URL为GONE,返回410HTTP状态码。
4) P 强制使用代理转发。
5) L 表明当前规则是最后一条规则,停止分析以后规则的重写。
6) N 重新从第一条规则开始运行重写过程。
7) C 与下一条规则关联8) T=MIME-type(force MIME type) 强制MIME类型
9) NS 只用于不是内部子请求
10) NC 不区分大小写
11) QSA 追加请求字符串
12) NE 不在输出转义特殊字符 \%3d$1 等价于 =$1

Apache虚拟主机下使用Rewrite实现Discuz伪静态的配置

第一步 :当然是配置Apache支持Rewrite功能,这个不多说了,就是:
LoadModule rewrite_module modules/mod_rewrite.so
原来有注释的就去掉注释,原来没有的添加上。
上面的配置中:
1.Options FollowSymLinks 这一步的配置必须有。
2.AllowOverride all 原来None的要改成all。
这两个配置缺一不可。
第三步 ,大家就比较熟悉了也不多说了,
就是在对应的目录下面添加.htaccess文件,下面以discuz为例说明:
RewriteEngine On
RewriteBase /
RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
RewriteRule ^tag-(.+)\.html$ tag.php?name=$1

第四步 :配置Discuz使用伪静态:
登录后台管理,进入“全局”=》“优化配置”=》“搜索引擎优化”在原来URL静态化的地方选中,然后提交即可。

配置完毕,去discuz前台访问就可以了。原来的php都变成html了。

在apache配置文件中设置
复制代码 代码如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3
RewriteRule ^/home/(space|network)-(.+)\.html$ /home/$1\.php\?rewrite=$2
RewriteRule ^/home/(space|network)\.html$ /home/$1\.php
RewriteRule ^/home/([0-9]+)$ /home/space\.php\?uid=$1
RewriteRule ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2
</IfModule>

此文适用于Apache虚拟主机用户。
  在开始以下设置之前,首先应该确认服务器支持mod_rewrite以及支持对站点目录中.htaccess的文件解析,否则即便按照下面的方法设置好了,也无法使用。点击查看Apache下开启mod_rewrite的方法。
Apache下开启mod_rewrite
  服务器环境:Windows Server 2003 SP2 + Apache 2.0.59
  开启方法:
  用文本编辑器打开Apache安装目录\conf\httpd.conf,找到“#LoadModule rewrite_module modules/mod_rewrite.so”这行,去掉前面的“#”;继续查找“AllowOverride None”,修改为“AllowOverride All”;然后,重启Apache即可。

  检查论坛所在目录中是否存在.htaccess 文件,如果不存在,则手工建立此文件。在Win32系统下,无法直接建立.htaccess 文件,则可以从其他系统中拷贝一份,也可以点击这里下载我做的一个,解压缩后即可使用。编辑并修改.htaccess文件,添加以下内容 :
复制代码 代码如下:
# 将 RewriteEngine 模式打开
RewriteEngine On
# 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
RewriteBase /discuz
# Rewrite 系统规则请勿修改
RewriteRule ^archiver/([a-z0-9\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^profile-(username|uid)-(.+)\.html$ viewpro.php?$1=$2

  添加内容时,请遵照上面的提示,修改论坛所在的路径,然后保存。将.htaccess文件上传到论坛所在的目录中。进入论坛系统设置,根据需要开启URL静态化功能。

-=======================================================
注意下面必须得
复制代码 代码如下:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:\aaa\wwwroot"
ServerName *
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^ss-xs/([0-9]+)/spacelist(.*)$ /index.php?$1/action_spacelist$2
RewriteRule ^ss-xs/([0-9]+)/viewspace_(.+)$ /index.php?$1/action_viewspace_itemid_$2
RewriteRule ^ss-xs/([0-9]+)/viewbbs_(.+)$ /index.php?$1/action_viewbbs_tid_$2
RewriteRule ^ss-xs/([0-9]+)/(.*)$ /index.php?$1/$2
RewriteRule ^ss-xs/([0-9]+)$ /index.php?$1
RewriteRule ^ss-xs/action_(.+)$ /index.php?action_$1
RewriteRule ^ss-xs/category_(.+)$ /index.php?action_category_catid_$1
RewriteRule ^ss-xs/itemlist_(.+)$ /index.php?action_itemlist_catid_$1
RewriteRule ^ss-xs/viewnews_(.+)$ /index.php?action_viewnews_itemid_$1
RewriteRule ^ss-xs/viewthread_(.+)$ /index.php?action_viewthread_tid_$1
RewriteRule ^ss-xs/index([.a-zA-Z0-9]*)$ /index.php
</IfModule>
</VirtualHost>

=======================
复制代码 代码如下:
NameVirtualHost 124.129.183.146
<VirtualHost bbs..net.cn>
ServerName bbs..net.cn
DocumentRoot D:/WebSite/phpbbs
<Directory "D:/WebSite/phpbbs">
Options Indexes FollowSymLinks Includes
AllowOverride All
order allow,deny
Allow from all
</Directory>
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^ss-xs/([0-9]+)/spacelist(.*)$ /index.php?$1/action_spacelist$2
RewriteRule ^ss-xs/([0-9]+)/viewspace_(.+)$ /index.php?$1/action_viewspace_itemid_$2
RewriteRule ^ss-xs/([0-9]+)/viewbbs_(.+)$ /index.php?$1/action_viewbbs_tid_$2
RewriteRule ^ss-xs/([0-9]+)/(.*)$ /index.php?$1/$2
RewriteRule ^ss-xs/([0-9]+)$ /index.php?$1
RewriteRule ^ss-xs/action_(.+)$ /index.php?action_$1
RewriteRule ^ss-xs/category_(.+)$ /index.php?action_category_catid_$1
RewriteRule ^ss-xs/itemlist_(.+)$ /index.php?action_itemlist_catid_$1
RewriteRule ^ss-xs/viewnews_(.+)$ /index.php?action_viewnews_itemid_$1
RewriteRule ^ss-xs/viewthread_(.+)$ /index.php?action_viewthread_tid_$1
RewriteRule ^ss-xs/index([.a-zA-Z0-9]*)$ /index.php
</IfModule>
</VirtualHost>


  • 上一条:
    分享apache http服务器设置虚拟主机的方法
    下一条:
    Gzip在apache2中的设置和squid对它的处理
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客