我有一系列来自不同制造商的价格表(从数据库中吐出)。 它们每页限制为100行,即:
www.domain.com/products/price-lists/company1.php?page=2 www.domain.com/products/price-lists/company2.php?page=10我想重写为:
www.domain.com/products/price-lists/company1/page/2 www.domain.com/products/price-lists/company2/page/10我有:
Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^products/price-lists/company1/page/([0-9]+)/?$ products/price-lists/company1.php?page=$1 [NC,L] RewriteRule ^products/price-lists/company2/page/([0-9]+)/?$ products/price-lists/company2.php?page=$1 [NC,L]首先,如果我尝试去/ products / price-lists / company1 / page / 2(如果我删除/ page /它可以工作),则会抛出404,其次,我想知道我是否可以将它们合并为一条规则无论如何:
(company1|company2[0-9]+)/?感谢您的帮助(这是我的第一次mod_rewrite尝试!)
I have a series of price lists from various manufacturers (spat out from a database). They are limited to 100 rows per page, ie:
www.domain.com/products/price-lists/company1.php?page=2 www.domain.com/products/price-lists/company2.php?page=10which i want to rewrite to:
www.domain.com/products/price-lists/company1/page/2 www.domain.com/products/price-lists/company2/page/10I have:
Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^products/price-lists/company1/page/([0-9]+)/?$ products/price-lists/company1.php?page=$1 [NC,L] RewriteRule ^products/price-lists/company2/page/([0-9]+)/?$ products/price-lists/company2.php?page=$1 [NC,L]First of all, this throws a 404 if i try to go to /products/price-lists/company1/page/2 (it works if i remove /page/) and second, i was wondering if i could combine them into one rule anyway:
(company1|company2[0-9]+)/?Thanks for any help (this is my first mod_rewrite attempt!)
最满意答案
尝试这个:
Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^products/price-lists/([a-z0-9_\-]+)(/page)?/?$ products/price-lists/$1.php?page=1 [NC,L] RewriteRule ^products/price-lists/([a-z0-9_\-]+)/page/([0-9]+)/?$ products/price-lists/$1.php?page=$2 [NC,L]第一条规则将检查页面是否存在而没有编号并转到第1页。 ([a-z0-9_\-]+)将用于放置公司,因此如果您放置:
http://www.domain.com/products/price-lists/stackoverflow/page/2/products/price-lists/stackoverflow.php将使用$_GET['page'] = 2打开
Try this:
Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^products/price-lists/([a-z0-9_\-]+)(/page)?/?$ products/price-lists/$1.php?page=1 [NC,L] RewriteRule ^products/price-lists/([a-z0-9_\-]+)/page/([0-9]+)/?$ products/price-lists/$1.php?page=$2 [NC,L]The first rule will check if a page is there or not without a number and go to page 1. The ([a-z0-9_\-]+) will be use to put the company, so if you put:
http://www.domain.com/products/price-lists/stackoverflow/page/2the /products/price-lists/stackoverflow.php will open using $_GET['page'] = 2
更多推荐
发布评论