1

I have a new WordPress site, example.com, with the old Drupal site archived at archive.example.org. Many files on the old site had a URL like so (ex: example.org/files/foo.pdf), but all those links out there in the internet are breaking because all those file downloads need to be redirected to archive.example.org/files/foo.pdf.

Can creating redirects (I'm guessing .htaccess is the best bet) work for file downloads as well? Is there a simple redirect to send all old links to the archive subdomain?

I have tried:

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.org%{REQUEST_URI} [R,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
# END WordPress

...with no luck so far.

Thanks for any help!

Terence Devine
  • 115
  • 1
  • 13

1 Answers1

1

If you want to redirect all files/* requests to the new domain and keep everything else from WordPress, you need a condition for the rule, which checks for files

RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.com%{REQUEST_URI} [R,L]

When everything works as it should, you may replace R with R=301. Never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • Thanks for the help! I'm still not seeing the redirect taking effect, I've updated the question with my full `.htaccess` file. – Terence Devine Jul 01 '16 at 15:34
  • 1
    This is because the requests are already handled by the second rule, because of `RewriteCond %{REQUEST_FILENAME} !-f`. Move the rule to the beginning and it should work. – Olaf Dietsche Jul 01 '16 at 15:38
  • This still needs to be within the `If` and after the `RewriteEngineOn` right? I've updated the post with what I've got currently, but still no change. – Terence Devine Jul 01 '16 at 15:45
  • Do you have an Apache or Nginx server? – Olaf Dietsche Jul 01 '16 at 15:48
  • Did some sniffing around through my hosting (WP Engine) and it seems they've got a redirect system set up on their end... getting it sorted out now, thanks for your help! – Terence Devine Jul 01 '16 at 16:00