Reputation: 2859
I am trying to write a redirect for a PDF file in my wordpress install that has shown up in my google webmaster tools with a load of query strings after it, what I want is to have the redirect match any number or query stings after the pdf filename and just redirect directly to the file.
RewriteRule ^(.*) http://www.example.com/wp-content/uploads/2014/08/test\.pdf$ [R=301,L]
and this also (as well as numerous different iterations)
RedirectMatch 301 ^/wp-content/uploads/2014/08/test\.pdf(.*)$ /wp-content/uploads/2014/08/test.pdf?
However they either result in a continuous redirect loop, 404 error, or still leave part of the query string
the url has any number of random query strings so something that would catch anything after the filename and just redirect to the bare file is percisely what I am looking for. here is an example of the url:
or
and what I want to get is just
http://www.example.com/wp-content/uploads/2014/08/test.pdf
Thanks
Upvotes: 0
Views: 40
Reputation: 24448
Try something like this with mod_rewrite.
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} (.+)\.pdf$
RewriteRule ^(.*) /$1? [R=301,L]
Upvotes: 1