原文链接:http://faq.comsenz.com/viewnews-12

URL 静态化是一个利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 HTML 页面,当然,这里的静态化是一种假静态,目的只是提高搜索引擎的搜索量,Comsenz 旗下的产品 Discuz!、SupeSite/X-Space、ECShop、SupeV、UCHome 等都支持此功能。当然这个功能还需要服务器环境的支持,下面介绍一下如何在 Apache 服务器下配置 URL 静态化的 Rewrite 规则。

当然这里分两种情况,一种是独立主机用户,这部分用户拥有对主机的管理权限,因此配置起来比较方便一些。(注:这里就以 Discuz!6.1.0 的 Rewrite 规则为例,稍后在后面会列举出其他产品的 Rewrite 规则。

首先确定您使用的 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 ^(.*)/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 ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2
</IfModule>

如果没有安装 mod_Rewrite,您可以重新编译 Apache,并在原有 configure 的内容中加入 --enable-Rewrite=shared,然后再在 Apache 配置文件中加入上述代码即可。

另外一种用户是 Apache 虚拟主机用户。

在开始以下设置之前,请首先咨询您的空间服务商,空间是否支持 Rewrite 以及是否支持对站点目录中 .htaccess 的文件解析,否则即便按照下面的方法设置好了,也无法使用。

检查论坛所在目录中是否存在 .htaccess 文件,如果不存在,请手工建立此文件。Win32 系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 Discuz.net 技术支持栏目中下载此文件。编辑并修改 .htaccess 文件,添加以下内容:

# 将 RewriteEngine 模式打开
RewriteEngine On
# 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
RewriteBase /discuz
# Rewrite 系统规则请勿修改
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

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

下面简单介绍一些其他产品的 Rewrite 规则。

SupeSite/X-Space6.0 UC规则

Apache 独立主机用户:

<IfModule mod_Rewrite.c>
RewriteEngine On
###Rewrite 系统规则请勿修改
RewriteRule ^/([0-9]+)/spacelist(.+)$ /index.php?uid/$1/action/spacelist/type$2 [L]
RewriteRule ^/([0-9]+)/viewspace(.+)$ /index.php?uid/$1/action/viewspace/itemid$2 [L]
RewriteRule ^/([0-9]+)/viewbbs(.+)$ /index.php?uid/$1/action/viewbbs/tid$2 [L]
RewriteRule ^/([0-9]+)/(.*)$ /index.php?uid/$1/$2 [L]
RewriteRule ^/([0-9]+)$ /index.php?uid/$1 [L]
RewriteRule ^/action(.+)$ /index.php?action$1 [L]
RewriteRule ^/category(.+)$ /index.php?action/category/catid$1 [L]
RewriteRule ^/viewnews(.+)$ /index.php?action/viewnews/itemid$1 [L]
RewriteRule ^/viewthread(.+)$ /index.php?action/viewthread/tid$1 [L]
RewriteRule ^/mygroup(.+)$ /index.php?action/mygroup/gid$1 [L]
</IfModule>

Apache 虚拟主机用户:

### 将 RewriteEngine 模式打开
RewriteEngine On
### 修改以下语句中的 /SupeSite 修改为你的SupeSite目录地址,如果程序放在根目录中,请将 /SupeSite 修改为 /
RewriteBase /
### Rewrite 系统规则请勿修改
RewriteRule ^([0-9]+)/spacelist(.+)$ index.php?uid/$1/action/spacelist/type$2 [L]
RewriteRule ^([0-9]+)/viewspace(.+)$ index.php?uid/$1/action/viewspace/itemid$2 [L]
RewriteRule ^([0-9]+)/viewbbs(.+)$ index.php?uid/$1/action/viewbbs/tid$2 [L]
RewriteRule ^([0-9]+)/(.*)$ index.php?uid/$1/$2 [L]
RewriteRule ^([0-9]+)$ index.php?uid/$1 [L]
RewriteRule ^action(.+)$ index.php?action$1 [L]
RewriteRule ^category(.+)$ index.php?action/category/catid$1 [L]
RewriteRule ^viewnews(.+)$ index.php?action/viewnews/itemid$1 [L]
RewriteRule ^viewthread(.+)$ index.php?action/viewthread/tid$1 [L]
RewriteRule ^mygroup(.+)$ index.php?action/mygroup/gid$1 [L]

ECShop2.6.0 规则

Apache 独立主机用户:

<IfModule mod_Rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/index.html$ $1/index.php
RewriteRule ^(.*)/category$ $1/index.php [L]
RewriteRule ^(.*)/feed-c([0-9]+).xml$ $1/feed.php?cat=$2 [L]
RewriteRule ^(.*)/feed-b([0-9]+).xml$ $1/feed.php?brand=$2 [L]
RewriteRule ^(.*)/feed.xml$ $1/feed.php
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/category.php?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6&page=$7&sort=$8&order=$9
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)\.html$ $1/category.php?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/category.php?id=$2&brand=$3&page=$4&sort=$5&order=$6
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ $1/category.php?id=$2&brand=$3&page=$4
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)(.*)\.html$ $1/category.php?id=$2&brand=$3
RewriteRule ^(.*)/category-([0-9]+)(.*)\.html$ $1/category.php?id=$2
RewriteRule ^(.*)/goods-([0-9]+)(.*)\.html$ $1/goods.php?id=$2
RewriteRule ^(.*)/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/article_cat.php?id=$2&page=$3&sort=$4&order=$5
RewriteRule ^(.*)/article_cat-([0-9]+)-([0-9]+)(.*)\.html$ $1/article_cat.php?id=$2&page=$3
RewriteRule ^(.*)/article_cat-([0-9]+)(.*)\.html$ $1/article_cat.php?id=$2
RewriteRule ^(.*)/article-([0-9]+)(.*)\.html$ $1/article.php?id=$2
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html $1/brand.php?id=$2&cat=$3&page=$4&sort=$5&order=$6
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html $1/brand.php?id=$2&cat=$3&page=$4
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)(.*)\.html $1/brand.php?id=$2&cat=$3
RewriteRule ^(.*)/brand-([0-9]+)(.*)\.html $1/brand.php?id=$2
RewriteRule ^(.*)/tag-(.*)\.html $1/search.php?keywords=$2
RewriteRule ^(.*)/snatch-([0-9])\.html$ $1/snatch.php?id=$2
RewriteRule ^(.*)/group_buy-([0-9])\.html$ $1/group_buy.php?act=view&id=$2
</IfModule>

Apache 虚拟主机用户:

RewriteEngine On
#RewriteBase /
# direct one-word access
RewriteRule ^index\.html$ index\.php [L]
RewriteRule ^category$ index\.php [L]
# access any object by its numeric identifier
RewriteRule ^feed-c([0-9]+)\.xml$ feed\.php\?cat=$1 [L]
RewriteRule ^feed-b([0-9]+)\.xml$ feed\.php\?brand=$1 [L]
RewriteRule ^feed\.xml$ feed\.php [L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2 [QSA,L]
RewriteRule ^category-([0-9]+)(.*)\.html$ category\.php\?id=$1 [QSA,L]
RewriteRule ^goods-([0-9]+)(.*)\.html$ goods\.php\?id=$1 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2&sort=$3&order=$4 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2 [QSA,L]
RewriteRule ^article_cat-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1 [QSA,L]
RewriteRule ^article-([0-9]+)(.*)\.html$ article\.php\?id=$1 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html brand\.php\?id=$1&cat=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2&page=$3 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2 [QSA,L]
RewriteRule ^brand-([0-9]+)(.*)\.html brand\.php\?id=$1 [QSA,L]
RewriteRule ^tag-(.*)\.html search\.php\?keywords=$1 [QSA,L]
RewriteRule ^snatch-([0-9]+)\.html$ snatch\.php\?id=$1 [QSA,L]
RewriteRule ^group_buy-([0-9]+)\.html$ group_buy\.php\?act=view&id=$1 [QSA,L]
RewriteRule ^auction-([0-9]+)\.html$ auction\.php\?act=view&id=$1 [QSA,L]

SupeV1.0beta 规则

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>

Apache 虚拟主机用户:

# 将 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

UCHome1.0 规则

Apache 独立主机用户:

RewriteEngine On
RewriteRule ^/(space|network)\-(.+)\.html$ /$1.php?Rewrite=$2 [L]
RewriteRule ^/(space|network)\.html$ /$1.php [L]
RewriteRule ^/([0-9]+)$ /space.php?uid=$1 [L] 

Apache 虚拟主机用户:

RewriteEngine On
RewriteBase /
RewriteRule ^(space|network)\-(.+)\.html$ $1.php?Rewrite=$2 [L]
RewriteRule ^(space|network)\.html$ $1.php [L]
RewriteRule ^([0-9]+)$ space.php?uid=$1 [L] 

当然,在我们每个发布的程序包中,都有关于此版本程序对应的 Rewrite 规则,大家可以在那里找到相对应的 Rewrite 规则。

如何在Apache环境下配置Rewrite规则相关推荐

  1. 如何在 Windows 环境下配置 PHP 开发运行环境

    我们都知道 PHP 运行需要的环境通常被称为 AMP. 其中 A 是 Apache 应用服务器,M 是 Mysql,P 就是 PHP 了. 实际上,很多人可能会使用一个测试 Mysql,但是针对一些小 ...

  2. 雷林鹏分享:YAF 在Nginx环境下的Rewrite规则

    这2天在学习YAF框架,在nginx环境下参照手册配置rewrite规则后,访问页面出现404错误,最后发现是rewrite规则书写上出现了些错误. 手册提供的Nginx的Rewrite: serve ...

  3. apache环境下配置服务器支持https

    SSL加密的意义在于保护服务器到客户端的信息或者是客户端到服务器的信息不被监听和篡改. 现在一些主流的网站都已经是通过 https访问了,搜索引擎对此类网站的收录也不存在问题了. 具体的配置流程大概是 ...

  4. 从零搭建个人博客(3)-如何在webpack环境下配置jquery和富文本编辑器Simditor

    无论是博主自己写文章还是读者发表评论,都需要一个方便的编辑框,html自带的textarea和editable div都过于简单,本文将记录在webpack环境中添加jquery和Simditor的过 ...

  5. 【转载】Ubuntu环境下配置Android Studio

    之前学习Android开发的时候,一直跟各种教程一样,使用的是Eclipse+ADT,主要是比较方便,容易上手,特别是对于习惯用Eclipse开发java的朋友来说,上手更是好无压力.但毕竟Eclip ...

  6. linux https重定向,Linux | Apache环境下强制http跳转至https的配置总结

    如果网站安装SSL证书开启HTTPS后,不设置强制跳转的话,http和https会同时存在,那么如何在Apache Web环境下将HTTP强制跳转到HTTPS呢? 接下来将给给出使用.htaccess ...

  7. ubuntu 14.04 apache php mysql_Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方法

    本文实例讲述了Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方法.分享给大家供大家参考,具体如下: 这里为Ubuntu14.04系统下配置PHP7.0+Apac ...

  8. 如何在IIS环境下布置https

    昨天各位小伙伴都很开心的领取了自己的SSL证书,但是大部分小伙伴却不知道如何部署,也许是因为第一次接触SSL这种高端的东西吧,不过个人觉得就是懒懒懒...本来小编也挺懒的,但是答应了各位小伙伴的,那么 ...

  9. 如何在Mac环境下搭建svn服务器端环境

    为什么80%的码农都做不了架构师?>>>    在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境.在Mac环境下,由于Mac自带了svn的服务器端和客户端功 ...

最新文章

  1. Silverlight OA源代码(Silverlight4+SQLServer2005)
  2. 原来Python破解受密码保护的zip文件这么简单,不保证一定成功
  3. aliyun的maven下载jar的方法
  4. java索引序列_视图、序列、索引
  5. pandas 生成html表格_Pandas 读写html
  6. 2013-2014 ACM-ICPC Pacific Northwest Regional Contest题解
  7. JavaScript学习(三十一)—在输入框中如何判断输入的是一个正确的网址
  8. linux下 udf提权_raven靶机实战(linux-udf提权)-vuluhub系列(四)
  9. (超详细,避免踩坑)如何使用freeMaker模板生成器处理图片以及文字替换
  10. 插件地址(eclipse jrebel jed)、问题
  11. Barcode模块管理条码扫描识别
  12. 凭借UGC壮大的马蜂窝,亦是喜忧参半
  13. “死神”百草枯:每年超万人中毒 没有解药
  14. cmd打开记事本并写字_Windows中的记事本和写字板之间有什么区别?
  15. 利用jink的驱动软件j-flash 合并两个hex的方法,bootloader+app -(转载)
  16. 细粒度车型识别项目(基于DenseNet, 数据集Stanfordcars-196,准确率:95.00%)
  17. android pc 模拟器哪个好,安卓模拟器电脑版哪个好?
  18. MASA Framework - DDD设计(1)
  19. 7.12 C语言练习(爬动的蠕虫:一条蠕虫长1寸,在一口深为N寸的井的底部。已知蠕虫每1分钟可以向上爬U寸,但必须休息1分钟才能接着往上爬。)
  20. WPF入门第三篇 ControlTemplate、Trigger与Storyboard

热门文章

  1. 搜索目录里所有文件(包括子目录)
  2. 全国计算机等级考试题库二级C操作题100套(第74套)
  3. electron 打包_Vue3+Electron整合方式
  4. range函数python-Python for循环与range函数的使用详解
  5. 最详细的Mac下安装nacos教程来了
  6. pugixml解析Word
  7. SQL Server 2008 R2:快速清除日志文件的方法
  8. 程序默认在副屏显示_聊一款性价比极高的电竞显示器
  9. wpf 如何设置弹出窗口必须关闭才能打开其他软件_5招教你如何清除C盘除系统外的所有垃圾!都学会了吗?...
  10. java局部刷新session过期_Ajax局部页面刷新和History API结合的陷阱