2

I have a website using PHP-based CMS system.

So each page is generated dynamically, like this :

http://www.shuling.net.cn/index.php?_m=mod_product&_a=view&p_id=87

Now I want to redirect this specific page to another page, i.e.:

So I write .htaccess file as follows :

redirect 301 /index.php?_m=mod_product&_a=view&p_id=87 https://www.datanumen.com/sql-recovery/

But after I upload the .htaccess to the root directory of the website, this does not work at all.

I retest by writing another rule, like this:

redirect 301 /sql/ https://www.datanumen.com/sql-recovery/

Then this rule will work perfectly.

Why?

Thank you

1 Answer 1

1

Querystring is not part of match in Redirect directive, to redirect query strings, you need to use mod-rewrite as follows :

option 1

RewriteEngine on

RewriteCond %{THE_REQUEST} /index\.php\?_m=mod_product&_a=view&p_id=87 [NC]
RewriteRule ^ https://www.datanumen.com/sql-recovery/? [NC,L,R]

option 2

RewriteEngine on

RewriteCond %{QUERY_STRING} ^_m=mod_product&_a=view&p_id=87$ [NC]
RewriteRule ^index\.php$ https://www.datanumen.com/sql-recovery/? [NC,L,R]

We use an empty question mark ? at the end of the target url to discard the old query strings, otherwise these query strings get appened to the target url by default.

Change the R to R=301 if you want to make the redirection permanent.

[Tested on apache2 and 2.4]

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .