php - merge QUERY_STRING params with a regex matched param in htaccess -
i have .htaccess file redirecting urls this:
rewriterule ^companies/([0-9]{1,20})/(.*)/?$ /php/company-profile.php?id=$1 [nc,l] which matches url 'companies/12345/company-name-safe' , grabbing unique id company-profile.php.
this works great. include list of jobs company on page, has pagination & order_by functionality.
so need capture url params , pass php file.
e.g url: companies/12345/company-name?page=2&order_by=date+desc
i don't want have change url structure if possible, want page 1 clean url without '?id=12345' on end.
how can this?
you have add qsa flag rule
rewriterule ^companies/([0-9]{1,20})/(.*)/?$ /php/company-profile.php?id=$1 [nc,l,qsa] this way, query string appended. example companies/12345/company-name?page=2&order_by=date+desc rewritten /php-profile.php?id=12345&page=2&order_by=date+desc.
the solution above valid if query string parameters can have same names in rule. otherwise, can capture them separately rewritecond on %{query_string} , append them manually in rule, instance:
rewritecond %{query_string} ^page=([^&]+)&order_by=([^&]+)$ [nc] rewriterule ^companies/([0-9]{1,20})/(.*)/?$ /php/company-profile.php?id=$1&xxx_page=%1&xxx_order_by=%2 [nc,l] note in current case, don't need qsa flag anymore
Comments
Post a Comment