Regular Expression For URL Query

蹲街弑〆低调 提交于 2019-12-12 04:12:21

问题


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 the 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!


回答1:


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]


来源:https://stackoverflow.com/questions/3242410/regular-expression-for-url-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!