英文:
rewriterule friendly url with pagination
问题
我需要更改我的RewriteRule。
我有一个友好的重写URL:
RewriteRule ^homepage/([^/]+)$ /home.php?path=$1 [L]
它处理形式为/homepage/gite-di-1-giorno
的URL。
这个方法有效。但同一页还需要处理分页,例如:/homepage/gite-di-1-giorno?page=2
我尝试了这个:
RewriteCond %{QUERY_STRING} ^homepage/([^/]+)$&page=([0-9]+)
RewriteRule ^homepage/([^/]+)$&page=([0-9]+) /home.php?path=$1&page=$2 [L]
但$_GET["page"]
没有设置。
英文:
I need to change my rewriterule.
I have a rewrite friendly url:
RewriteRule ^homepage/([^/]+)$ /home.php?path=$1 [L]
Which handles URLs of the form /homepage/gite-di-1-giorno
.
This works. But same page has to handle pagination as well, for example: /homepage/gite-di-1-giorno?page=2
I tried this:
RewriteCond %{QUERY_STRING} ^homepage/([^/]+)$&page=([0-9]+)
RewriteRule ^homepage/([^/]+)$&page=([0-9]+) /home.php?path=$1&page=$2 [L]
but $_GET["page"]
is not set.
答案1
得分: 0
只需将 QSA
(Query String Append)标志添加到您的原始规则中即可。例如:
RewriteRule ^homepage/([^/]+)$ /home.php?path=$1 [QSA,L]
QSA
标志会将原始请求的查询字符串(如果有)与您在替代字符串中设置的查询字符串合并。因此,形式为 /homepage/gite-di-1-giorno?page=2
的请求会在内部重写为 /home.php?page=gite-di-1-giorno&page=2
。
参考链接:
英文:
It would seem you just need to add the QSA
(Query String Append) flag to your original rule. For example:
RewriteRule ^homepage/([^/]+)$ /home.php?path=$1 [QSA,L]
The QSA
flag appends (merges) the query string on the original request (if any) with the query string you are setting in the substitution string. So, a request of the form /homepage/gite-di-1-giorno?page=2
is internally rewritten to /home.php?page=gite-di-1-giorno&page=2
.
Reference:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论