Redirecting PDF Files with .htaccess, PHP, and ASP
How to Redirect PDF Files with .htaccess, PHP, and ASP
Redirecting PDF files with .htaccess, PHP, and ASP can be a tricky process. This article will provide an overview of the different methods for redirecting PDF files, and how to go about implementing them. We will look at how to use .htaccess to redirect PDF files, as well as how to use PHP and ASP to achieve the same result.
Ensuring files are correctly redirected is extremely important for SEO, as managing it correctly will ensure you increase your conversion rates and also keep your site user friends for users and search engines.
301 Redirects
When it comes to SEO, the best redirect to use is a 301 permanent redirect. This is because search engines still have trouble handling 302 temporary redirects. And don’t even think about using a Meta Tag Refresh redirect or a redirect generated by a client-side language such as JavaScript if you care about search engine optimization.
.htaccess 301 Redirect
This is the easiest and most straightforward option to use, but it’s only available on a Linux server. Simply add the line below to your .htaccess file.
Redirect 301 /oldfile.pdf http://www.example.com/newpage.html
PHP 301 Redirect
This is also normally a pretty easy way to redirect pages by adding a couple lines of PHP on each page you want to redirect. But since PHP code cannot actually be inserted into the PDF file, we have to treat it a bit differently. Follow the steps below:
1. Rename oldfile.pdf file to filename2.pdf.
2. Create a new directory named “oldfile.pdf” in the same directory that the PDF is in.
3. Add an index.php file in the new oldfile.pdf directory.
4. Add the following PHP code to the top of the index.php file:
<?
Header( “HTTP/1.1 301 Moved Permanently” );
Header( “Location: http://www.example.com/
new-page-to-redirect-to.php” );
?>
Now when the search engines access http://www.example.com/oldfile.pdf they will actually be served the http://www.example.com/oldfile.pdf/index.php file which contains the 301 redirect to the new page.
ASP 301 Redirect
This is very similar to the steps for the PHP 301 redirect above, but this is websites that are hosted on Windows servers and use ASP.
1. Rename oldfile.pdf file to filename2.pdf.
2. Create a new directory named “oldfile.pdf” in the same directory that the PDF is in.
3. Add an index.asp file in the new oldfile.pdf directory.
4. Add the following ASP code to the top of the index.asp file:
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.example.com/
new-page-to-redirect-to.asp”
%>
Now when the search engines access http://www.example.com/oldfile.pdf they will actually be served the http://www.example.com/
oldfile.pdf/index.asp file which contains the 301 redirect to the new page.