Tushar Korat
Tushar Korat

Reputation: 581

htaccess redirection when URL has ? query string

From URL with pattern-

http://example.com/top-100-selenium-interview-questions-answers.html?format=pdf

I want to redirect to

http:// example.com/istqb_dump.pdf

I have created redirect following rule.

RewriteCond %{QUERY_STRING} format=pdf [NC]
RewriteRule .* http:// example.com/istqb_dump.pdf? [R=301,L]

It was working fine.

Now there are other URL as well like below -

http://example.com/top-35-seo-interview-questions/?format=pdf

http://examplecom/top-15-digital-marketing-interview-questions/?format=pdf

That I want to redirect to respective URL live

http:// example.com/seo.pdf

http:// example.com/digital-marketing.pdf

But with above rule, all URL are redirect to

http:// example.com/istqb_dump.pdf

How can I configure induvial redirection?

Upvotes: 2

Views: 124

Answers (1)

Bananaapple
Bananaapple

Reputation: 3114

You need to make you RewriteRule more specific, creating a bespoke condition for each case:

RewriteCond %{QUERY_STRING} format=pdf [NC]
RewriteRule ^top-100-selenium-interview-questions-answers.html /istqb_dump.pdf? [R=301,L]

RewriteCond %{QUERY_STRING} format=pdf [NC]
RewriteRule ^top-35-seo-interview-questions/? /seo.pdf? [R=301,L]

RewriteCond %{QUERY_STRING} format=pdf [NC]
RewriteRule ^top-15-digital-marketing-interview-questions/? /digital-marketing.pdf? [R=301,L]

Demo here: http://htaccess.mwl.be?share=97bf4828-2ec0-551e-8bc1-4fb9f2f0f278

Upvotes: 1

Related Questions