RewriteRule适用于分页页面

时间:2013-06-15 00:08:01

标签: apache .htaccess

我正在尝试定义RewriteRule

在网站内我有这样的网页:

index.php?pag=company&id=853

我已经定义了这个规则:

RewriteRule ^/([a-zA-Z0-9])/([0-9]+)$index.php?pag=company&id=$2 [NC, L]

试图得到这个结果:

company/university-of-gloucestershire/1656

此规则有效,但不适用于分页页面,例如:

index.php?pag=company&id=853&page=2

我试过了:

RewriteRule ^/(.*)/([0-9]+)/([0-9]+)$ index.php?pag=company&id=$2&page=$4 [NC, L]

尝试前往:

company/university-of-gloucestershire/1656/page/2

有谁可以指出什么是错的?

1 个答案:

答案 0 :(得分:0)

看起来像一个错字。您的示例规则中不存在$4分页。此外,如果这是.htaccess,则不应该存在初始斜杠。 .*贪婪,所以我用任何字符替换它,而不是/

RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)$ index.php?pag=$1&id=$3&page=$5 [NC,L]

company/university-of-gloucestershire/1656/page/2将成为:

index.php?pag=company&id=1656&page=2

该规则需要先于此规则,因为您仍然必须抓住某人未指定页码的页面:

RewriteRule ^([^/]+)/([^/]+)/([0-9]+)(/page/?)?$ index.php?pag=$1&id=$3&page=1 [NC,L]

company/university-of-gloucestershire/1656/

company/university-of-gloucestershire/1656/page将成为:

index.php?pag=company&id=1656&page=1