Need a way to 301 redirect http://mysite.com/index.htm to http://www.mysite.com/index.htm

Discussion in 'Site Design, SEO, Google and Site Promotion' started by mluirette, Aug 23, 2006.

  1. I'm trying to find an easy way to 301 redirect the default page of an HTML website from http://example.com/index.htm to http://www.example.com/index.htm.

    How would I set up an ASP or ASPX file to do this?

    All posts in the forum say to "put this in your global.asax", and any time someone asks "what's that?" they say, "oh, you can only do that with asp".

    Anyone find an easy way to do this? I didn't realize this would be such an issue moving from an apache server. I'm going crazy trying to keep link partners to remember the WWW!

    Any help at all would be greatly appreciated!! thx in advance.[​IMG]
     
  2. Bruce

    Bruce DiscountASP.NET Staff

  3. Bruce

    Bruce DiscountASP.NET Staff

    unfortunately, this is not possible because www.domain.com and domain.com are just host header of the same site.


    What you need to do is to create some logic w/ ASP or ASP.NET to redirect appropiately.


    We can, if you wish, remove the host header for domain.com. This means only www.domain.com will work.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  4. Thanks for the quick answer Bruce!


    Unfortunately, we need the www.domain.com AND domain.com to work for the same page somehow without it looking like two duplicate pages. Customers use the domain.com, link partners use both (arg!), one version ranks well, and the other doesn't, it'sa mess! We can't lose half the link pop due to a technical glitch. We need to combine the two with a 301-redirect somehow. I want the non-WWW version to appear as "permanently moved" to the WWW when spiders come crawling around and to transfer pagerank.


    Any examples on how to put together something like this? Something I could look at, modify, and upload would be great! Sorry for being a novice at ASP.net, but what goes in the Global.asax file, where do I put it on the server, and how do I call up the subroutine from the page? Is there a basic Global file I can upload and modify?


    It seems like there should be tons of examples of other people fixing this problem, and I've found working examples, but I can't seem to find a complete set of instructions.


    I found this post through google: http://community.discountasp.net/default.aspx?f=5&m=8525


    On the reply from "markus", there's this code for the global.asax file:


    'Check for www
    If Request.Url.ToString.IndexOf("www.") < 0 Then


    Dim mypage As String = Request.Url.ToString.Insert(Request.Url.ToString.IndexOf("//") + 2, "www.")


    'Check if URL is like http://mysite.com/default.aspx (You want to have consistent linking / redirecting. Therefore we cut off
    the "/default.aspx" bit)


    If myPage.ToLower.EndsWith("/default.aspx") Then
    myPage = myPage.Substring(0, myPage.IndexOf("/default.aspx"))
    End If


    Response.Redirect(myPage)
    Response.StatusCode = 301


    'The restof the global.asax should be ignored as events will be fired again after the redirect....
    Exit Sub
    End If


    Where does it go in the file? I can't get it to work. How do I call the file from an aspx page?


    Thanks again in advance! Sorry for all the questions.


    -Mike
     
  5. Try putting the code in the Application_BeginRequest in the global.asax

    <script language="vb" runat="server">
    Sub Application_BeginRequest(Sender as Object, E as EventArgs)
    ...
    End Sub
    </script>


    <script language="C#" runat="server">
    void Application_BeginRequest(object source, EventArgs e) {
    ...
    }
    </script>



    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  6. OK, I'd love to do that, DiscoutASPhas access to the server but already told me this is not allowed in ashared environment. I need to accomplish this task somehow:
    IIS Redirect
    <UL class=defaultfont>
    [*]In internet services manager, right click on the file or folder you wish to redirect (http://signs4success.com/)
    [*]Select the radio titled "a redirection to a URL".
    [*]Enter the redirection page (http://www.signs4success.com/)
    [*]Check "The exact url entered above" and the "A permanent redirection for this resource"
    [*]Click on 'Apply' [/list]
    Please repeat for each non-WWW version ofall thesehttp://www.bootycocktails.com/, http://www.divasfashions.com/, http://www.divascostumes.com/,http://www.bootdungeon.com/ , http://www.mistersprockets.com/, http://www.hbdentalimplants.com/.

    This is why I'm frustrated. Is this possible to get DiscountASP to do this?

    If not, how can I get the same effect with HTML/Javascript pageson their server?

    Can I at least get the non-WWW versions of the URLs to land on a different page so I can usea simple Javascript code to accomplish this?

    Thank you!
     
  7. Hi Joel -

    The only thing in the global.asax is the code I copied here below. I have no idea what else is supposed to be in a global.asax file, because all the sites are HTML and I never had one to begin with.

    I need to start at super-dumb level and work my way to something workable for at least the index page, I don't even care if the other pages won't do this!

    1. How do I make and where do I put the global.asax file
    2. Where do I put the code below in the global file
    3. How do I convert a standard HTML page into an ASPX page that will pull up this code and work?

    I just need to get this one task done, then I'll have all the time in the world to learn ASP.net and leave you guys alone. Thank you for being so patient!

    Here's the only thing I could find to supposedly do what I need to do. If there'sa better way, please tell me I'm wrong and correct me:



    'Check for www
    If Request.Url.ToString.IndexOf("www.") < 0 Then


    Dim mypage As String = Request.Url.ToString.Insert(Request.Url.ToString.IndexOf("//") + 2, "www.")


    'Check if URL is like http://mysite.com/default.aspx (You want to have consistent linking / redirecting. Therefore we cut off
    the "/default.aspx" bit)


    If myPage.ToLower.EndsWith("/default.aspx") Then
    myPage = myPage.Substring(0, myPage.IndexOf("/default.aspx"))
    End If


    Response.Redirect(myPage)
    Response.StatusCode = 301


    'The restof the global.asax should be ignored as events will be fired again after the redirect....
    Exit Sub
    End If
    Thanks again!
    -Mike
     
  8. 1. I still need you to paste your global.asax here...
    2. Your code should replace the '...' in one of theApplication_BeginRequest methods.
    3. I don't understand this question.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  9. Sorry, but my biggest problem is I don't have a global.asax file, or any "Application_BeginRequest" methods.


    I have plain-old html files and I just need to 301 redirect from http://xyz.comto http://www.xyz.com, but I keep being told your server can't do this. Now I need to find some workaround, and I don't care how, just something I can integrate into an html plain-old static page website.


    Lets start from the beginning so we're talking about the same thing here: How do I 301-redirect a url missing the WWW to a url with the WWW?


    Everyone in the forums and in tech support keeps telling me I need to do something "programmatically" to fix it. Is there a way to do this programmatically in a static HTML file? The next answer I received was I need to convert to ASP.net to make this work. This is where question #3 came from.


    I keep getting the same answer to put stuff in my global file, and then we go around in circles again.


    I really don't want to change services, and I think your the best host I've had, but this is a MAJOR problem if it can't be fixed somehow. Every other hosting company I've had utilized some sort of search-engine-friendly redirect to avoid this problem. Isn't there anything similar to an htaccess file in IIS or something to fix this without going through all this?


    I copied the only thing I had, which was the same code I found in the old forum posting.
    If this isn't what you need, please tell me where to get it and I'll find one somewhere.


    Thanks!


    -Mike
     
  10. You may map you htm pages to aspx.You may issue a ticket to the DASP support for this.You could then create a global.aspx.

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  11. So, please tell if I'm getting this right:

    I take the code sample I found and save it in a file called "global.asax" and upload to the server.
    Next I take this:


    <script language="vb" runat="server">
    Sub Application_BeginRequest(Sender as Object, E as EventArgs)
    ...
    End Sub
    </script>


    <script language="C#" runat="server">
    void Application_BeginRequest(object source, EventArgs e) {
    ...
    }
    </script>

    and insert in somewhere (above the <html> tag?) in the current "index.htm" file and rename itto "index.aspx"?

    I get a error: Parser Error Message: The content in the application file is not valid.

    Probably because I'm not even close to doing this right!
    What else am I missing?

    Thanks again!
    -Mike
     
  12. Eventually we'll be migrating portions of the store to ASP.net. For now, we need the HTML pages.
    It would be great if I could get the two to co-exist on the same server with proper URL forwarding.


    We can't afford risking the nameserver switch with our busy season coming up, otherwise I'd switch immediately then come back when the ASP is ready. From experience, this could cause a temporarylossof our positioning completely from the search engines, especially Google. The last changeover I saw was sales-death.


    What will I expect to see as an effect of "mapping HTM pages to ASPX"?
    Will the URL change to a .aspx file? If this is the case, I'll lose the advantage of doing this to begin with because it'll be seen as a different URL, or worse, duplicate content.[​IMG]
    Well, thanks for all the help, but it looks like this will not be practical for us. I guess I'll have to keep hunting down link partners and correcting them!

    If mapping means keeping the .htm extensions, that'll be awesome! Let me know....

    -Mike
     
  13. Oh, BTW Joel, when I said "super-dumb" I was referring to ME, not you! Just in case that's what prompted the harsh reply. Thanks man! [​IMG]
     
  14. Bruce

    Bruce DiscountASP.NET Staff

    i have to be honest w/ you, if you have just plain old static page site, why are you hosting your site on our server?


    Not that we don't want your business but I am speaking from a technical perspective. If you do not need ASP or ASP.NET technology, you are better off hosting your static site on an UNIX box where you can easily perform URL Rewriting.


    The way I look at it is simple, there is no ultimate platform out there, you choose the most suitable platform for your every need. I can tell you that if you have a plain old HTML site, you better off hosting it on a UNIX platform.


    Changing .html mapping will definintely work but you also need to write a custom HTTP Handler in ASP.NET to handle the HTML page.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  15. Bruce

    Bruce DiscountASP.NET Staff

    When we map an extension to ASP.NET, the page will be processed by the ASP.NET processor. In another, you cancreate a custom HTTP Handler in your application to do whatever you want with the page.


    Yes. Technically, this is possible.

    I found some reference that may help

    http://www.15seconds.com/issue/020417.htm
    http://geekswithblogs.net/flanakin/articles/HttpHandlers.aspx
    http://www.developerfusion.co.uk/show/4643/


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  16. Great! Thank you for all the help...


    Since my ASP guy won't (or can't!)help with this, we're about ready to tell him and his cart to take a hike.
    We're weighing our options at this time, but if we stick with the plan to migrate to ASP.net I'll definitely use the advice.


    Keep up the good work, and thanks again for putting up with my ramblings! It's much appreciated.


    -Mike
     
  17. Bruce

    Bruce DiscountASP.NET Staff

    No problem!!


    This google problem is bugging a lot of people and we are also trying to find ways to make it easier for our customer.


    The big problem is that URLRewriting is not part of IIS and it requires some pretty hard core programming ability to write your own rewrite tool.


    Good luck!

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  18. Any update on 301 Redirects? I'd like to make www.brockhuman.com and all subsequent URIs always redirect to brockhuman.com.

    How about just letting us set different folders for different sub-domains. Then a proper 301 is a simple PHP, or ASP (I assume) file away!

    Thanks, Ed

    edified.org
     
  19. Bruce

    Bruce DiscountASP.NET Staff

    unfortunately, it doesn't work this way.


    the hostname and www.hostname are just simply host header in the IIS virtual server, and they are technically equivalent.


    If we give different sub directory w/ each hostname, that means we have to setup multiple virtual server which requires a complete change in architecture.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  20. We can do that. Create a support ticket.

    Although you should alsoremove the www "A Record" in the DNS Manager so that it won't get resolved to the default site on the server, which displays a generic "web page unavailable" page.

    Aristotle

    DiscountASP.NET
    www.DiscountASP.NET
     
  21. Does anyone have an update to the 301 redirect issue?

    If DiscountAsp cannot come up with a good solution,they willhave a serious competetive disadvantage to other .NET framework hosting companies. SEOs will definitely think twice before useing DiscountAsp hosting, as others who specialize in .NET hosting offer a solution to 301 redirect.

    Please advise. Thanks.
     
  22. Bruce

    Bruce DiscountASP.NET Staff

    The problem is not related to a 301 redirect problem. The problem is that both www.domain &amp; domain is the SAME site (they are just different host header).


    I think almost all hosts have the same problem.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  23. PRB

    PRB

    What .NET host provides the ability to use the 301 redirect on their shared servers?
     
  24. At this time, I do not know of any. If I did I would probably be using their services - all things being equal.


    It looks to me like this is a rather large opportunity for some hot shot.NET hosting co. (like DiscountAsp) to create a good solution. What with all the concern google has createdabout duplicate content (www.mysite.com and mysite.com).


    That you ask the question, makes my point. [​IMG]
     
  25. Here is the solution...

    Contact support and have themmap all .htm and .html pages to the ASP.net ISAPI.

    Create a new file called global.asax...

     
  26. That was fast! I'll implement the code later today. Thanks.
     
  27. Joel - could you translate that into VB? Please.
     
  28. Hi Joel - well there two reasons I asked:


    1) As I understand it, I can only use one language in the global.asax file, and I will be adding more code (in VB) later.


    2) I would like to better understand what your code does.


    Thanks
     

Share This Page