简体   繁体   中英

.htaccess redirect GET parameters and PDFs

I have a few links from an old site - asp files with parameters in querystring - I wan them redirected to my new WordPress site.

For Example

http://www.example.com/admin/m_sito/sample/down.asp?file=catalogue_de.pdf to http://www.example.com/wp-content/uploads/doc/catalogue_de.pdf.pdf

here is the code that is not working with variables in them. Any ideas?

RewriteCond %{QUERY_STRING} ^file=catalogue_de.pdf$
RewriteRule ^admin/m_sito/sample/down\.asp$ /wp-content/uploads/doc/catalogue_de? [R=301,L]

You should try this answer :-

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^/admin/m_sito/sample/down\.asp$
RewriteCond %{QUERY_STRING} ^file=catalogue_de.pdf$
RewriteRule ^(.*)$ /wp-content/uploads/doc/catalogue_de [R=302,L]

For the General case you can use this :-

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^/admin/m_sito/sample/down\.asp$
RewriteCond %{QUERY_STRING} ^file=(.*)$
RewriteRule ^(.*)$ /wp-content/uploads/doc/%1.pdf [R=302,L]

May me it will helpful.

A little bit improved version of Harsh Sanghani's answer:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/admin/m_sito/sample/down\.asp$
RewriteCond %{QUERY_STRING} ^file=(.*)$
RewriteRule .* /wp-content/uploads/doc/%1? [R=301,L]

I moved the code at the begin of the .htaccess file and it works

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/admin/m_sito/sample/down\.asp$
RewriteCond %{QUERY_STRING} ^file=(.*)$
RewriteRule .* /wp-content/uploads/doc/%1? [R=301,L]

thank you very much :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM