Search code examples
apache.htaccessmod-rewriteurl-rewriting

rewriterule friendly url with pagination


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.


Solution

  • 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: