1

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.

1 Answer 1

2

Use this rule:

RewriteCond %{QUERY_STRING} ^m=[01]$ [NC]
RewriteRule ^(.*)$ /$1? [R=301,L,NC]
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Anubhava, thnx.. but there are many ursls and Nokia.html is just one exapmple, I have around 300+ urls which ends with differently like samsung.html, tablet.html, so plz edit the code accordingly..
Hi Anubhava, thnx a ton it worked perfect. There is one more add on to this needed. in home pages there is no html in end of the url and hence this code doesnt work. like www.abc.co.in/?m=0 OR www.abc.co.in/?m=1 Can u plz give the code for just these 2 urls. I have to use this also for same domain. best rgds
Hi Anubhava, EXCELLENT, its works perfectly fine, thnx a ton....God bless u buddy, have grt time... best rgds, Jai

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.