1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

htaccess redirect if not found

Discussion in 'Apache' started by Cequiel, Apr 22, 2012.

  1. #1
    Hi All,
    I have been investigating about a problem and I have no idea how to solve it. I would like to define a rule in the .htaccess file to solve the following situation:

    If the user enters the following url:
    mypage

    I would like the system redirects to the following one:

    folder1/mypage/

    and in the case that 'folder1/mypage' does not exist, redirects to the following one:

    folder1/folder2/mypage/

    is that possible?
    Thank you.
     
    Cequiel, Apr 22, 2012 IP
  2. crungureanu

    crungureanu Greenhorn

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #2
    I don't know how to do it modifying the data in .htaccess, but I will show you a way to do it in html.






    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>LIFE COVER SURVEY</title>
    <meta http-equiv="refresh" content="0;url=yourpageXXXXXXXXXXXXX">

    </head>


    <body>
    <p>
    Redirecting to latest newsletter. If you're not redirected within a couple of seconds,
    click here:<br />
    <a href="yourpageXXXXXXXXXXXXX">CLICK HERE IF YOU ARE NOT REDIRECTED IN 5 SECONDS</a>
    </p>


    </body>




    Replace "yourpageXXXXXXXXXXXX" with your "folder1/mypage".
    Now, if this page does not exist, the server will redirect the visitor to "not_found.html" (or something similar). So, you have 2 options, depending on your needs: 1. put all the information from "folder1/folder2/mypage" on "not_found.html" or, 2. create a new redirect from this page to "folder1/folder2/mypage".

    The only problem with this is that every time somebody goes to a page that does not exist on your website , they will get to "folder1/folder2/mypage".

    Sorry, I'm not an expert in html :), but I hope this helps.
     
    crungureanu, Apr 22, 2012 IP
  3. BuenaBe

    BuenaBe Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yess you can..edit your httaccess
     
    BuenaBe, Apr 22, 2012 IP
  4. Cequiel

    Cequiel Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks. I finally used an alternative pattern.
     
    Cequiel, Apr 23, 2012 IP
  5. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Can you provide the pattern you used? To help others with similar problems as you.
     
    PK-Host, Apr 25, 2012 IP
  6. Cequiel

    Cequiel Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi PK-Host. My solution has nothing to do with with my original question :) I used another approach to avoid this situation.
     
    Cequiel, Apr 25, 2012 IP
  7. LauD.

    LauD. Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    very usefull , thanks
     
    LauD., May 8, 2012 IP