I want to rewrite some dynamic urls like:






You can rewrite a query string like this:

Example for one arbitrary parameter:

RewriteCond %{REQUEST_URI} ^/my-custom-url.html.*$
RewriteCond %{QUERY_STRING} ^(.*)=(.*)$
RewriteRule .* /my-custom-url.html/%1/%2? [R=301,NC,L]

Example for 3 arbitrary parameters:

RewriteCond %{REQUEST_URI} ^/my-custom-url.html.*$
RewriteCond %{QUERY_STRING} ^(.*)=(.*)&(.*)=(.*)&(.*)=(.*)$
RewriteRule .* /my-custom-url.html/%1/%2/%3/%4/%5/%6? [R=301,NC,L]
  • It replaced the URL well but now I am not able to get these parameter values via $_GET or $_REQUEST – Yogita Jun 2 '20 at 9:36
  • OK, that was not part of your question :-) For that you need an additional line, for example this for one parameter: RewriteRule ^/my-custom-url.html/[a-z]+/[a-zA-Z0-9-]+$ my-custom-url.html?$1=$2 [L] Important: this should not redirect! Put it above the other rule I'm not sure about this, it might end in an infinite loop – HelgeB Jun 2 '20 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.