Deprecated: Assigning the return value of new by reference is deprecated in /home/jlhdes/public_html/wp-settings.php on line 520

Deprecated: Assigning the return value of new by reference is deprecated in /home/jlhdes/public_html/wp-settings.php on line 535

Deprecated: Assigning the return value of new by reference is deprecated in /home/jlhdes/public_html/wp-settings.php on line 542

Deprecated: Assigning the return value of new by reference is deprecated in /home/jlhdes/public_html/wp-settings.php on line 578

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/jlhdes/public_html/wp-settings.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /home/jlhdes/public_html/wp-settings.php:520) in /home/jlhdes/public_html/wp-content/plugins/bad-behavior/bad-behavior/screener.inc.php on line 8

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jlhdes/public_html/wp-settings.php:520) in /home/jlhdes/public_html/wp-content/plugins/wp-referer.php on line 36

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jlhdes/public_html/wp-settings.php:520) in /home/jlhdes/public_html/wp-content/plugins/wp-referer.php on line 36
Page by Page redirects in IIS for .asp, .html, .pdf, etc. | JLH Design
  • JLH Design

  • Page by Page redirects in IIS for .asp, .html, .pdf, etc.

31st January 2008

Page by Page redirects in IIS for .asp, .html, .pdf, etc.

posted in Webmastering |

Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

I’ve gone over adding a domain wide 301 redirects before in IIS to fix the www and non-www canonicalization issues, but the same issue also comes up for individual pages as well.

For an old page that is a .asp page adding the following code to the top of the page will perform the redirect. You can get rid of all other content on the page, as no browser or crawler will see it once they receive the 301 redirect.


<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", " http://www.example.com/newpage.asp"
Response.End
%>

That only works for pages with extensions set up to parse the asp code. A lot of times, specially on shared hosting environments, other pages with static extensions such as .html, .pdf, .txt, etc will not execute the code. With a little trickery we can accomplish that as well.

Let’s say you have the old file that you want to 301 redirect, for example:

www.example.com/old_directory/oldpage.html

Which you’d like to redirect to the new location:

www.example.com/new_directory/newpage.html

If you were to add the above code to newpage.html nothing would happen, or even the code would show up as text on the page, as more than likely your server is not set up to execute the code. Here’s what you can do:

  1. Delete (or rename it to save it for a rollback) the oldpage.html file located in /old_directory/
  2. Create a new sub-folder (note: it’s a folder not a file) under /old_directory/ with the same name as the file you just deleted, in this example you’d create a sub-folder named ‘oldpage.html’ like /old_directory/oldpage.html/.
  3. In that folder you just created you will then create a default asp file to execute the redirect code, this can be different depending on how your site is set up, but generally it is default.asp, such as you now have a page located at /old_directory/oldpage.html/default.asp
  4. in that default.asp you will want to add the following code:


<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", " http://www.example.com/new_directory/newpage.html"
Response.End
%>

That’s it you’re done. Now when someone or a crawler visits the old page, they will be 301 redirected to the new location. As stated before this also works for other static pages such as .PDF, .DOC, .TXT, .HTM , etc.

For example if you visit this page, which appears like it was a PDF:

www.hvac-direct.com/pdfs/oldfile.pdf

You should be automatically redirected to a new html file in a folder:

http://www.hvac-direct.com/html-version/

To see that is actually a 301 redirect view the response on the oyoy.eu tools. Note: that it’s a double redirect because of the lack of trailing slash on that server set-up, but it’s better than returning a 404!

This entry was posted on Thursday, January 31st, 2008 at 4:53 pm and is filed under Webmastering. You can follow any responses to this entry through the RSS 2.0 feed. All comments are subject to my NoFollow policy. Both comments and pings are currently closed.

There are currently 5 responses to “Page by Page redirects in IIS for .asp, .html, .pdf, etc.”

Why not let me know what you think by adding your own comment! All the cool kids are doing it.

  1. 1 MyAvatars 0.2 On February 2nd, 2008, Sebastian said:

    Neat trick, John. I’d add
    Response.End
    because with a 301 header the user agent won’t look at the content you output.

  2. 2 MyAvatars 0.2 On February 2nd, 2008, John Honeck "JLH" said:

    Done! Thanks.

  3. 3 MyAvatars 0.2 On February 2nd, 2008, g1smd said:

    I am not in favour of a double redirect, but if you really have to, then this method should work.

    Be aware that PageRank doesn’t appear to be passed through any sort of redirection chain like this.

  4. 4 MyAvatars 0.2 On February 2nd, 2008, John Honeck "JLH" said:

    g1smd, I’m not a big fan of chain redirects either, but it’s been said by Bergy (a Googler) that Google will at least recognize them, not sure about PageRank transfer. He did say, “…it should be appropriately passing PageRank and other signals on to the new pages. This process might take just a little longer for double-redirected URLs than it would for single-redirected URLs, but you might not even notice a significant diafference between this and other URL restructurings that you’ve set up. ”

    I don’t know about the other engines, MSN seems to have a brain freeze when it comes to handling simple things like this.

  5. 5 MyAvatars 0.2 On February 5th, 2008, Forrest said:

    One thing - and you got this right - is that it’s important to include Response.End after actually sending down the redirect. Some user agents will work anyway, while others will choke. ( In other words, just because your browser seems okay doesn’t mean GoogleBot will be. )

    MSN sadly seem to have a brain freeze for a lot of things. My photo blog shows traffic from MSN for searches for dog pain killers. ( That could be clever referral spam…? )

    Back to ASP and ASP.NET, while the latter allows HttpHandlers to use VB or C# code in place of ISAPI filters … you can use some logic in a custom 404 page to manage your redirects. I tend to keep either a list of pages, or reg ex patterns, in an xml file or in the database, then have the logic in the 404 page scan that against the requested url before it decides what to do: send a 301 redirect, or a 404 error.

  • Please Support

  • Marquette University

  • Sponsored

125x125

  • Donations


  • ;

Enter your email address:

Delivered by FeedBurner

rss posts
Spread the Word
Sphinn
delicious
digg
technorati
reddit
magnolia
stumbleupon
yahoo
google
  • Readers