How do I 301 redirect an html.index to a php in same domain?

Discussion in 'HTML & Website Design' started by rbf738, Sep 14, 2009.

  1. #1
    Let's just use hypothetical examples because I've found a number of pages explaining 301 redirects, but I'm doing something wrong, so I'll just have someone respond if possible with my example.

    So I want to redirect my old url: www.randomsite.com/chapstick/index.html

    to

    www.randomsite.com/lipstick.php

    Can someone show me the exact code to do this including my examples...I'm afraid i'm a bit daft for it to work any other way. Thanks so much!
     
    rbf738, Sep 14, 2009 IP
  2. Gamernz

    Gamernz Active Member

    Messages:
    305
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^randomsite.com/chapstick/index.html [nc]
    rewriterule ^(.*)$ www.randomsite.com/lipstick.php$1 [r=301,nc] 
    Code (markup):
    Add this into your htaccess in the root of the public_html.

    Also notice with the randomsite URL there is no http:// or www in front of it.
     
    Last edited: Sep 14, 2009
    Gamernz, Sep 14, 2009 IP
  3. rbf738

    rbf738 Peon

    Messages:
    475
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I created an htaccess file, put in the code making the changes and everything, but it's not working. Where do I upload it to on my server/what do you mean public_html? In the chapstick folder or the randomsite folder on my server?
     
    rbf738, Sep 14, 2009 IP
  4. rbf738

    rbf738 Peon

    Messages:
    475
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Does it make a difference if I have windows or hosting or what not?

    I'm running Windows Vista, I use dreamweaver for html editing, use notepad to create a .htaccess file, and use godaddy hosting.

    Please someone help me with this!
     
    rbf738, Sep 14, 2009 IP
  5. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It matters what godaddy is using. Apache? Which version?

    Gamernz,
    I didn't understand the $1 after the lipstick.php in the rewrite... is something supposed to come after lipstick.php?? I understand it's a capture but what is iti supposed to be capturing?
     
    Last edited: Sep 15, 2009
    Stomme poes, Sep 15, 2009 IP
  6. rbf738

    rbf738 Peon

    Messages:
    475
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm not sure what it is, I emailed them for more assistance about this whole redirect thing as I've tried sooo many suggestions and methods but I must be doing something wrong every single time because every time I try going to the old page hoping for a redirect it's still there, same as always!
     
    rbf738, Sep 15, 2009 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That's a good idea. Apache isn't the only server out there. A Windows server likely runs IIS (though you can also run Apache on it). There are also other servers out there like lighttpd and nginx.
    There are two major versions of Apache: 1.3 and 2.x, and I've heard that there's a difference between them whether you start your patter with ^/ or just ^. You can be safe and do ^/? (slash is an option) which works for either version. (if ServerSignature is on, your 404 page should state what server you're using and which version, so you can also go to a page you know doesn't exist and see if the signature after the error is there).
     
    Stomme poes, Sep 16, 2009 IP
  8. minervait

    minervait Peon

    Messages:
    85
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    use .htaccess or get in touch with me
     
    minervait, Sep 16, 2009 IP
  9. rbf738

    rbf738 Peon

    Messages:
    475
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Godaddy mailed me back and said: The hosting account you are currently running is a Windows shared hosting account. With the Windows based hosting, you will want to use the ASP code for the redirect, as PHP runs off of the Linux hosting accounts. Below is the code they gave me in an earlier email:

    ASP Code - save this as oldpagename.asp

    <%@ Language=VBScript %>
    <%
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "http://www.new-url.com"
    %>

    SO USING MY EXAMPLE FROM EARLIER IT SHOULD LOOK LIKE:

    Saved as chapstick.asp

    <%@ Language=VBScript %>
    <%
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "http://www.randomsite.com/lipstick.php"
    %>

    Does this look correct?

    Where do I upload it to on my server considering it's for the same domain? The root folder of "randomsite"?

    THANKS FOR HELPING ME EVERYONE!
     
    rbf738, Sep 16, 2009 IP
  10. pneulameiro

    pneulameiro Peon

    Messages:
    440
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It will work. You have to upload it to the chapstick folder and save it default.asp or index.asp.
     
    pneulameiro, Sep 16, 2009 IP
  11. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Well actually wouldn't you want to put it where the old url is? The point is, when people go to www.randomsite.com/chapstick/index.html you want those people to get the redirect, right? So that ASP code they gave you should have the same name as that file (index.html), in the chapstick folder like pneulameiro said.

    If the file is called "index.asp" and people go looking for "index.html" they shouldn't be getting the redirect as those would be two different files, wouldn't they?
     
    Stomme poes, Sep 17, 2009 IP