ecshop伪静态规则如何实现?

2009年4月5日  | 标签: ,

最近在用ecshop开发一个商城,源码中提供了通过 .htaccess来启动url重写。但是考虑到以后的性能和安全问题:
1、性能:如果AllowOverride启用了.htaccess文件,则Apache需要在每个目录中查找.htaccess文件,因此,无论是否真正用到,启用.htaccess都会导致性能的下降。另外,对每一个请求,都需要读取一次.htaccess文件。还有,Apache必须在所有上级的目录中查找.htaccess文件,以使所有有效的指令都起作用;即使这些文件都不存在。也会导致性能的下降。

2、安全:这样会允许用户自己修改服务器的配置,这可能会导致某些意想不到的修改,所以请认真考虑是否应当给予用户这样的特权。但是,如果给予用户较少的特权而不能满足其需要,则会带来额外的技术支持请求,所以,必须明确地告诉用户已经给予他们的权限,说明AllowOverride设置的值,并引导他们参阅相应的说明,以免日后生出许多麻烦。

我决定使用httpd 设置来启用url重写,关于ecshop的urlrewrite整理如下:
您可根据自己服务器的版本去修改httpd.conf或httpd-vhosts.conf

<VirtualHost *:80>
DocumentRoot D:/web/ecshop
ServerName a.ecshop.com

 <IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteRule /category-([0-9]+)-b([0-9]+)(.*)\.html$  /category\.php\?id=$1&brand=$2

 #RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)(.*)\.html$ $1/category\.php\?id=$2&brand=$3

 #RewriteRule /news_(\d+)\_(\d+)\.html /news\.php\?sID=$1\&pageNo=$2
 RewriteRule /feed-c([0-9]+)\.xml$       /feed\.php\?cat=$1
 RewriteRule /feed-b([0-9]+)\.xml$       /feed\.php\?brand=$1
 RewriteRule /feed\.xml$                 /feed\.php

 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

 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

 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

 RewriteRule /category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ /category\.php\?id=$1&brand=$2&page=$3

 RewriteRule /category-([0-9]+)-b([0-9]+)(.*)\.html$ /category\.php\?id=$1&brand=$2 

 RewriteRule /category-([0-9]+)(.*)\.html$ /category\.php\?id=$1 

 RewriteRule /goods-([0-9]+)(.*)\.html$ /goods\.php\?id=$1

 RewriteRule /article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$           /article_cat\.php\?id=$1&page=$2&sort=$3&order=$4 

 RewriteRule /article_cat-([0-9]+)-([0-9]+)(.*)\.html$ /article_cat\.php\?id=$1&page=$2  

 RewriteRule /article_cat-([0-9]+)(.*)\.html$ /article_cat\.php\?id=$1  

 RewriteRule /article-([0-9]+)(.*)\.html$ /article\.php\?id=$1  

 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

 RewriteRule /brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html /brand\.php\?id=$1&cat=$2&page=$3

 RewriteRule /brand-([0-9]+)-c([0-9]+)(.*)\.html /brand\.php\?id=$1&cat=$2
 RewriteRule /brand-([0-9]+)(.*)\.html /brand\.php\?id=$1

 RewriteRule /tag-(.*)\.html /search\.php\?keywords=$1

 RewriteRule /snatch-([0-9]+)\.html$ /snatch\.php\?id=$1

 RewriteRule /group_buy-([0-9]+)\.html$ /group_buy\.php\?act=view&id=$1

 RewriteRule /auction-([0-9]+)\.html$ /auction\.php\?act=view&id=$1

 RewriteRule /exchange-id([0-9]+)(.*)\.html$ /exchange\.php\?id=$1&act=view

 RewriteRule /exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$            /exchange\.php\?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6

 RewriteRule /exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$                                /exchange\.php\?cat_id=$1&page=$2&sort=$3&order=$4

 RewriteRule /exchange-([0-9]+)-([0-9]+)(.*)\.html$ /exchange\.php\?cat_id=$1&page=$2 

 RewriteRule /exchange-([0-9]+)(.*)\.html$ /exchange\.php\?cat_id=$1 

   </IfModule>

</VirtualHost>

类别(php编程) | 浏览(1,001) | 发表评论 | Trackback
目前还没有任何评论.