开发者

Regular Expression For URL Query

开发者 https://www.devze.com 2023-01-07 05:54 出处:网络
I\'ve been using mod_rewrite in my htaccess file to rewrite my urls and I\'ve run into a problem when doing pagination.

I've been using mod_rewrite in my htaccess file to rewrite my urls and I've run into a problem when doing pagination.

Here's th开发者_StackOverflow社区e url for my page: http://domain.com/concerts/features/folk-roots?page=2

htaccess file:

RewriteRule ^features/([^/]*)?page=([0-9]*)$ featureCat.php?cat=$1&page=$2 [NC,L]

It works fine without the page query, but if I want to change pages I can't figure out how to write the regular expression to grab the page #.

Any ideas would be appreciated!


You need to use RewriteCond immediately before the RewriteRule to get access to the query string:

RewriteCond %{QUERY_STRING} ^page=([0-9]*)$
RewriteRule ^features/([^/]*)$ featureCat.php?cat=$1&page=%1 [NC,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消