如何一次重写大量的URL?(How to rewrite numerous URL's at once?)

系统教程 行业动态 更新时间:2024-06-14 16:54:47
如何一次重写大量的URL?(How to rewrite numerous URL's at once?)

我有一系列来自不同制造商的价格表(从数据库中吐出)。 它们每页限制为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=10

which i want to rewrite to:

www.domain.com/products/price-lists/company1/page/2 www.domain.com/products/price-lists/company2/page/10

I 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/2

the /products/price-lists/stackoverflow.php will open using $_GET['page'] = 2

更多推荐

本文发布于:2023-04-08 12:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/795925af05752a131e2823c8b9910a30.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   URL   numerous   rewrite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!