0

I've tried everything but just can't seem to get things right :( I have over 800 urls and I need to rewrite them to point to a simple pdf file. Currently, I have links to:

http://subdomain.mydomain.com/?type=pdf&id=id123
http://subdomain.mydomain.com/?type=epub&id=id123

and I need this :

http://subdomain.mydomain.com/pdf/id123.pdf
http://subdomain.mydomain.com/epub/id123.epub

I've read through the htaccess and rewriterule Reference pages but I am still missing something. I can't remove the end string (?type=pdf&id=id123)

This is what I have :

RewriteCond %{QUERY_STRING} ^type=pdf&id=(.*)$ 
RewriteRule /?$ pdf/%1.pdf

And ofcourse it wrongly outputs:

 http://subdomain.mydomain.com/pdf/id1234.pdf?type=pdf&id=id123

I can't get rid of ?type=pdf&id=id123 at the end

Any help in the right direction would be fully appreciated.

0

Try adding flag query string discard [QSD]:

RewriteRule /?$ pdf/%1.pdf [QSD]
  • Thank you but that doesn't seem to make a difference :( I can't seem to get the redirect working via .htaccess locally - nothing happens – Heather Carrigan Valentin May 17 '18 at 12:55
  • You should also be able to replace the query string by ending the replacement with ? (an empty query string).To get some debug output for rewrite set the config to LogLevel warn rewrite:trace8. – meuh May 17 '18 at 13:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.