0

I have this link https://career.guru99.com/top-50-oops-interview-questions/?format=pdf

I want to redirect it to https://career.guru99.com/pdf/top-50-oops-interview-questions.pdf

I created the following htaccess rule

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

But the challenge is I have 200+ links and I will have to manually add so many entries in the htacess which also slow down the site. Is there some regular expression that can help with this?

I want /?format=pdf to be replaced with .pdf

2 Answers 2

3

Could you please try following, written and tested with shown samples. I am going through variable THE_REQUEST and getting appropriate format value from it then while rewriting placing its value.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s(.*?)/\?format=([^\s]*)\s [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/%2%1.%2 [NE,QSD,L]
Sign up to request clarification or add additional context in comments.

Comments

3

I want /?format=pdf to be replaced with .pdf:

You may try this rule:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^format=(pdf)$ [NC]
RewriteRule ^([\w-]+)/?$ /%1/$1.%1? [R=301,END,NE]

1 Comment

RewriteRule ^([\w-]+)/?$ /%1/$1.%1? [R=301,END,NE] because he ask for file type in the end.

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.