Answer the question
In order to leave comments, you need to log in
What should be the regular expression for RewriteRule to rewrite a specific GET parameter?
There is a URL like /news?page=3&utm=ex
Task: redirect all similar URLs to /news/page-3?utm=ex
In this case, the page parameter can be placed anywhere, i.e. it is not necessary to be the first after the question mark and of course it can be the only parameter, or it can be one of the set ... Tell me
how the RewriteRule rule is formed
Answer the question
In order to leave comments, you need to log in
If you need to remove only page from %{QUERY_STRING}, and leave the rest of the parameters as they are.
RewriteCond &%{QUERY_STRING} ^(.*?)&page=([^&]+)(.*)
RewriteCond /$1/page-%2?%1%3 ^(.+?\?)&*(.*)
RewriteRule ^(news)$ %1%2 [R=301,L]
RewriteCond %{QUERY_STRING} ^()page=([^&]+)&*(.*) [OR]
RewriteCond %{QUERY_STRING} ^(.*?)&page=([^&]+)(.*)
RewriteRule ^(news)$ /$1/page-%2?%1%3 [R=301,L]
&
at the end of the line ?utm=ex&
, then it will do.RewriteCond %{QUERY_STRING} ^(|.*?&)page=([^&]+)&*(.*)
RewriteRule ^(news)$ /$1/page-%2?%1%3 [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question