12
2012
10

ECshop 2.7.2实现简单URL重写-伪静态

ECshop 2.7.2实现简单URL重写-伪静态
* 一、找到Apache 服务器

1、首先您需要找到 Apache 安装目录,之后找到 conf 目录下的 httpd.conf 文件。
2、将下面的代码复制到 httpd.conf 文件中,注意将 /ecshop 替换为您的商店的实际
安装目录。

<Directory /ecshop>
Options FollowSymLinks
AllowOverride All
</Directory>

3、在 httpd.conf 中搜索 LoadModule rewrite_module,将该行前面的 # 号删除。
如果您的 Apache 是1.3.x版本还需要查找 AddModule mod_rewrite.c,
请将前面的#删除。
4、保存 httpd.conf。
5、将 ecshop 目录下的 htaccess.txt 重命名为 .htaccess。(windows下面可能没办法创建,我们可以把此文件在本机上建成htaccess.txt ,再写入RewriteBase /    再把这个文章传上空间再把文件改名成为 .htaccess   ,如果是在本机测试再把这个文件下载下来,放在根目录下即可。)
6、重新启动 Apache。
7、进入 ecshop 管理中心->商店设置,将 URL 简单重写设置为启用。

如果您想通过 httpd.conf 来设置重写规则,请按照下面的步骤操作:
1、执行上面第1-3步操作。
2、找到您的商店所在的虚拟主机段,如:
DocumentRoot “D:/php/xampp/htdocs”

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the “default” to be a very restrictive set of
# features.
3、将下面的内容加入在此段代码后面。

<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 [QSA,L]
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 [QSA,L]
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 [QSA,L]
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$                                        $1/category.php?id=$2&brand=$3&page=$4 [QSA,L]
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)(.*)\.html$                                            $1/category.php?id=$2&brand=$3 [QSA,L]
RewriteRule ^(.*)/category-([0-9]+)(.*)\.html$                                 $1/category.php?id=$2 [QSA,L]
RewriteRule ^(.*)/goods-([0-9]+)(.*)\.html$                                  $1/goods.php?id=$2 [QSA,L]
RewriteRule ^(.*)/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/article_cat.php?id=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^(.*)/article_cat-([0-9]+)-([0-9]+)(.*)\.html$                   $1/article_cat.php?id=$2&page=$3 [QSA,L]
RewriteRule ^(.*)/article_cat-([0-9]+)(.*)\.html$                            $1/article_cat.php?id=$2 [QSA,L]
RewriteRule ^(.*)/article-([0-9]+)(.*)\.html$                                $1/article.php?id=$2 [QSA,L]
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 [QSA,L]
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html                $1/brand.php?id=$2&cat=$3&page=$4 [QSA,L]
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)(.*)\.html                         $1/brand.php?id=$2&cat=$3 [QSA,L]
RewriteRule ^(.*)/brand-([0-9]+)(.*)\.html                                   $1/brand.php?id=$2 [QSA,L]
RewriteRule ^(.*)/tag-(.*)\.html                                             $1/search.php?keywords=$2 [QSA,L]
RewriteRule ^(.*)/snatch-([0-9]+)\.html$                                     $1/snatch.php?id=$2 [QSA,L]
RewriteRule ^(.*)/group_buy-([0-9]+)\.html$                                  $1/group_buy.php?act=view&id=$2 [QSA,L]
RewriteRule ^(.*)/auction-([0-9]+)\.html$                                    $1/auction.php?act=view&id=$2 [QSA,L]
</IfModule>

通过这种方法可以实现,ECshop URL简单重写,达到伪静态的目的。

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。