加入收藏 | 设为首页 | 会员中心 | 我要投稿 东莞站长网 (https://www.0769zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

(康盛产品)如何在Apache环境下配置Rewrite规则

发布时间:2021-03-30 07:47:25 所属栏目:教程 来源:网络整理
导读:p class="content"URL 静态化是一个利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 HTML 页面,当然,这里的静态化是一种假静态,目的只是提高搜索引擎的搜索量,Comsenz 旗下的产品 Discuz!、SupeSite/X-Space、ECShop、Su
副标题[/!--empirenews.page--]

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


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


<p class="content">


<p class="content">首先确定您使用的 Apache 版本,及是否加载了 mod_Rewrite 模块。


<div class="content">Apache 1.x 的用户请检查 conf/httpd.conf 中是否存在如下两段代码:
<div class="content">
LoadModule Rewrite_module libexec/mod_Rewrite.so
AddModule mod_Rewrite.c

<p class="content">Apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码:


<p class="content">LoadModule Rewrite_module modules/mod_Rewrite.so


<p class="content">如果存在,那么在配置文件(通常就是 conf/httpd.conf)中加入如下代码。此时请务必注意,如果网站使用通过虚拟主机来定义,请务必加到虚拟主机配置,即 中去,如果加在虚拟主机配置外部将可能无法使用,改好后将 Apache 重启。


<div class="content">

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

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]

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

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

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]

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

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

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]

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]

UCHome2.0 规则

(编辑:东莞站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读