301 redirect

Discussion in 'ASP.NET 2.0' started by cae, Mar 23, 2007.

  1. cae

    cae

    Anybody can tell me how can I do (manually and or using the control panel) 301 redirect to htm pages so they will direct to same name pages with aspx extension?
    Obviously using discountASP.net servers.
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Not exactly sure what you mean.

    Do you mean you want to redirect all .htm page to .aspx page? eg. if someone hit somepage.htm, it redirect to somepage.aspx


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. cae

    cae

    Bruce:

    Yes, I want to 301 redirect all my htm pages with to aspx with same name. Of course this is once I set up the aspx pages.
    I have a web site with all files with htm extensions. With this new ASP features with Expression Web, I thought I switch to windows hosting. But I am finding a simple 301 redirect with linux servers is a problem or at least I do not know how. I appreciate your help, there are few more problems but this is the main thing and I am almost ready to go back to my Linux server.
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    OK... there's a few ways to do that.

    1) Create a ASP.NET HTTPHandler to do the redirect. Are you familiar w/ coding in ASP.NET? This can get complicated.

    OR

    2) Insert a meta refresh on each page.

    Add something like this to the page,

    <meta HTTP-EQUIV="refresh" CONTENT="0;URL=http://www.domain.com/somepage.aspx">

    OR

    3) Add code to programatically redirect.

    a) Request support to map .html to ASP.NET ISAPI
    b) Add following code to each page

    <%
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", "http://www.domain.com" &amp; Request.ServerVariables("URL").replace(".html", ".aspx")
    Response.End
    %>






    Bruce

    DiscountASP.NET
    www.DiscountASP.NET

    Post Edited (bruce [DASP]) : 3/23/2007 10:27:35 PM GMT
     
  5. cae

    cae

    Bruce

    Thank you for your reply. Your response gave me hope. I realy want to use the new Expression Web asp.net componenets so I hope this works. Can you give be little bit more feedback to below before I contact support.

    2) this one works but it is not SEO friendly, may do more harm than good.

    1) this one is too much for me, have no idea how to do this.

    3) This one says 301 in the code you gave me here soshould be seo friendly. This is something I can handle with little more input.

    a)if they map this .html file for me, will it stay there dormant, meaning it will not hurt anything as I am not ready yet to make to swich to aspx pages. Anything specific to tell them other than request "map .html to ASP.NET ISAPI".
    b) When I am ready, I assume I willenter below code http://www.domain.com/somepage.aspx rather than "http://www.domain.com" as shown below to the htm pages I like to redirect and to htm pages I do not enter will not be redirected.



    <%
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", "http://www.domain.com" &amp; Request.ServerVariables("URL").replace(".html", ".aspx")
    Response.End
    %>


    Thank you vey much for your help.
     
  6. Bruce

    Bruce DiscountASP.NET Staff

    No. When you map html to asp.net, it will be treated as asp.net file.


    You'll need to create a simple HTTP handler if you want it to work as an html file.
    You probably need to do this all at once.

    I don't think the meta refresh will hurt google ranking though but that just my view.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  7. cae

    cae

    Bruce:
    Thank you for your reply, my question again is due to my lack of knowledge can you clear this in beginners language and detail. I will go with your #3 suggestions:

    1- I will request support to map .html to ASP.NET ISAPI and once they do this...
    2- Will there be any effect how my web pages work, html pages work or anything else unless, I put that 301 direct code to the html pages.
    3- More specifically any html pages that I do not put that 301 code will work as html pages as before this mapping or not?
    4- Also my pages mostly .htm I know they are same but should I tell them map.htm rather than htmlto ASP.net ISAP or not.
    5- In short, realy I hate to tell suppot to map.html... and suddenly find out my html web pagesare not working properly. I really like to first test this with one or two html 301 redirect to asp.x pages. I hate to change all layout and find out 301 redirect does not work.


    Again the last answer you gave me below, I did not undertsand anything due to my minimum knowledge. I use front page / expresion web now and without knowing much, I get by but up till now my linux host I could do most of this kind of stuf from cpanel so I appreciate your very simplistic explanation. Thanks.



    No. When you map html to asp.net, it will be treated as asp.net file. ?


    You'll need to create a simple HTTP handler if you want it to work as an html file. ?
    You probably need to do this all at once. ?
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    OK.. i did some simple test and have better solution for you.

    1) Ask support to map .htm or .html to the ASP extension (not asp.net)

    The problem with asp.net is that you need to create a handler which is quite painful

    2) Your .htm page should continue to work as is until you put the code in

    3) Put the following code instead (syntax is slightly different between asp / asp.net) to the page you want to redirect


    <%
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", "http://www.domain.com" &amp; replace(Request.ServerVariables("URL"),".htm", ".aspx")
    Response.End
    %>


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  9. cae

    cae

    Bruce:

    Thank you very much.

    I asked support what you suggest. I cut and pasted soI do not change anything by mistake.As soon as, they let me know I will try and let you know.

    Thanks again.
     
  10. cae

    cae

    Bruce:


    Support mapped it as you suggested. Everything working great. Also, I checked with a seo tool to see if it is search engine friendly, it is. I really appreciated your help. Thank you very much.</o:p>
    </o:p>
     
  11. Bruce

    Bruce DiscountASP.NET Staff

  12. Just a quick note for all of you who are interested in incorporating a 301 permenant redirects. IIS 7 does have a 301 permenant redirect capability. It will work with non .net web applications, standard .htm and .html pages. No extension mapping or redirect coding is required. I suggest that anyone that has discountasp account should really take advantage of the IIS 7 beta trial. Its free and you start learning about IIS 7 and all its neat features.
     
  13. Nice thread. Great idea Bruce :)
     
  14. If .htm and .html are mapped to .asp, are there any 'gotchas' or changes needed in the existing html pages?
     

Share This Page