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

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

扫码添加渲大师小管家,免费领取渲染插件、素材、模型、教程合集大礼包!

一 打开 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.zzvips.com [NC]
RewriteRule ^/(.*) http://www.zzvips.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中伪静态配置和使用(Apache虚拟主机下Discuz伪静态)(Apache 伪静态)
在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 webmaster@domain.com
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.zzvips.com>
ServerName bbs.zzvips.com
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>

分享到 :
相关推荐

在线网站安全检测(网站安全检测)

作者无意间发现一个检查网站案例的工具:百度云扫描平台。可以为站长提供网站的安全检查[...

境外服务器租用为什么深受站长青睐(境外服务器租用为什么深受站长青睐呢)

境外服务器租用深受站长青睐的原因有:1。境外服务器不需要备案。能省去繁琐的网站备案过...

高防服务器有什么特点(高防服务器有什么特点和作用)

高防服务器的特点1.高防服务器机房出口带宽冗余多。可扩展性大。防御ddos攻击能力[...

海外服务器IP地址为什么会被封(国外服务器ip被国内封禁)

海外服务器IP地址会被封的原因:1。使用海外服务器过程中违反海外服务器机房所处国家的...

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注