I am non ech guy and trying to get a rewrite code which I can use in htaccess for file specific parameter. Basically there are some urls with "?m=0" OR "?m=1" which I want to redirect. Like
Old url: www.abc.com/nokia.html?m=1
New URL: www.abc.com/nokia.html
Old url: www.abc.com/nokia.html?m=0
New URL: www.abc.com/nokia.html
I want to redirect code which is applied only when these 2 specific m=1
OR m=0
are present. In case there is any thing else than m=1
or m=0
, the redirect shall not get applied.
I am using:
RewriteCond %{THE_REQUEST} \ /([^\?\ ]*)\?
RewriteRule ^ /%1? [L,R=301]
But it gets applied in all urls and hence I can access admin pages where " ? " is used with other parameter.
Can anyone plz mention the code which I can use in very specific cases. Thanks in advance.
Use this rule:
RewriteCond %{QUERY_STRING} ^m=[01]$ [NC]
RewriteRule ^(.*)$ /$1? [R=301,L,NC]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.