I'm fairly new to .htaccess, but have gotten close to what I need, but am now stuck.
Input: https://www.example.com/p/mypage.html
Output: https://www.example.com/mypage
This is achieved with the following:
# Static pages: Remove /p from path and remove .html
RewriteRule ^p(/.*?)(?:\.html)?$ $1 [R=301,L]
# All other posts just remove .html
RewriteCond %{REQUEST_URI} ^/(.+)\.html?$ [NC]
RewriteRule ^ /%1 [L,R=301]
However, very often there is a query parameter m=1 that needs removed IF IT IS PRESENT
I need that query parameter removed for both static pages AND other posts in the above RewriteRules. Note that there very often may be other query parameters also present but that I do not want those to be removed.
Example 1:
Input: https://www.example.com/p/mypage.html?param1=a&m=1¶m2=b
DESIRED output: https://www.example.com/mypage?param1=a¶m2=b
Example 2:
Input: https://www.example.com/2019/12/mypage.html?param1=a&m=1¶m2=b
DESIRED output: https://www.example.com/2019/12/mypage?param1=a¶m2=b
In both of the above examples, all of the following are removed:
/pif present.htmlif presentm=1if present (sometimes it may be the only query parameter so that also needs taken into account)
(By the way, the above three bullets will be useful for anyone moving a site over from Blogger / Blogspot to Wordpress, as they represent the differences in how the paths and pages are handled)
Very much appreciate any help with the m=1 being removed if present.