Prestashop可以在apache主机中通过.htaccess控制url重写规则, 从而实现友好链接显示. 但如果是nginx主机, .htaccess 是无效, 但我们可能通过nginx.conf来控制重写.
要实现Prestashop在nginx中的url重写, 只要在nginx.conf相应的主机中加入以下重写代码就可以了.
rewrite ^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2$3.jpg last;
rewrite ^/([0-9]+)\-([0-9]+)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2.jpg last;
rewrite ^/([0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/c/$1$2.jpg last;
rewrite "^/lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$3&isolang;=$1$5" last;
rewrite "^/lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$2&isolang;=$1$4" last;
rewrite "^/lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /category.php?id_category=$2&isolang;=$1" last;
rewrite ^/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$2$4 last;
rewrite ^/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$1$3 last;
rewrite ^/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /category.php?id_category=$1 last;
rewrite ^/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /cms.php?id_cms=$1 last;
rewrite ^/([0-9]+)__([a-zA-Z0-9-]*)(.*)$ /supplier.php?id_supplier=$1$3 last;
rewrite ^/([0-9]+)_([a-zA-Z0-9-]*)(.*)$ /manufacturer.php?id_manufacturer=$1$3 last;
rewrite "^/lang-([a-z]{2})/(.*)$ /$2?isolang=$1" last;
由于我使用的是lnmp 设置的环境,所以我把上面的rewrite部分保存为一个Prestashop.conf 放在/usr/local/nginx/conf 下以方便管理,然后修改我的域名的.conf文件为(XXXXX部分改为你自己的域名):
server
{
listen 80;
server_name www.XXXXX.com shop.XXXXX.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.XXXXX.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
include Prestashop.conf;
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log off;
}
从上面可以看得出, Prestashop在 nginx中实现重写也很简单的.
十一月 8th, 2011 on 下午 11:53
An extra 1 bites the detritus, or at minimal another web log post bites the dust. Your weblog rocks my article meshing hold up the terrifying drives .