How Do I Redirect To Different File In Htaccess

Discussion in 'Apache' started by Darkside619, Jan 27, 2013.

  1. #1
    So, I would like my htaccess file to check if a file exists and if it doesn't then redirect to another file. How would I go about doing this?
     
    Darkside619, Jan 27, 2013 IP
  2. MilesWeb

    MilesWeb Well-Known Member

    Messages:
    869
    Likes Received:
    36
    Best Answers:
    7
    Trophy Points:
    173
    #2
    You can set a 404 redirect so that if any file does not exist it redirects to your index page. The landing page can by any one you want.

    Add the code in .htaccess


    This can be achieved from your hosting provider's control panel.
     
    MilesWeb, Jan 27, 2013 IP
  3. Darkside619

    Darkside619 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3


    But, I don't want a redirect to the index page. I want a redirect to a different file. Like say for instance that I have the same file located in two different folders, possibly one on another server. Let's say that just incase one of the files doesn't exist it'll load the other one. How can I do that?
     
    Darkside619, Jan 27, 2013 IP
  4. MilesWeb

    MilesWeb Well-Known Member

    Messages:
    869
    Likes Received:
    36
    Best Answers:
    7
    Trophy Points:
    173
    #4
    Change the index.php to the file you want to. You can change the landing page they way you want to. I mentioned index page just for an example.
     
    MilesWeb, Jan 27, 2013 IP
  5. Darkside619

    Darkside619 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5


    Can you write out an example since that's what I'm looking for. So, if file a doesn't exist, redirect to file b but actually have the whole thing written out. Thank you.
     
    Darkside619, Jan 28, 2013 IP
  6. MilesWeb

    MilesWeb Well-Known Member

    Messages:
    869
    Likes Received:
    36
    Best Answers:
    7
    Trophy Points:
    173
    #6
    Use something as below.

     
    MilesWeb, Jan 28, 2013 IP