How to 301 redirect a pdf file in htaccess

How to 301 redirect a PDF file with mod_alias and mod_rewrite

Here’s some quick information on how to use an Apache .htaccess file to do a 301 redirect with either mod_rewrite or mod_alias. This method should also work for .doc and .docx files as well.

mod_rewrite

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/old/path/file.pdf$
RewriteRule ^(.*) /new/path/file.pdf [L,R=301]

mod_alias

Redirect 301 /old/path/file.pdf /new/path/file.pdf

Leave a Reply

avatar
  Subscribe  
Notify of