0

我正在尝试定义一个 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

谁能指出什么问题?

4

1 回答 1

0

看起来像一个错字。$4您的分页示例规则中不存在。此外,如果这是 in .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
于 2013-06-15T02:38:16.287 回答