skip to Main Content

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


  1. 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]
    
    Login or Signup to reply.
  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search