Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Redirect Page

  • 28-03-2006 11:04AM
    #1
    Registered Users, Registered Users 2 Posts: 1,452 ✭✭✭


    Ok My brain is on a "no work please" day......

    Simple problem I would have thought. I have 2 domains pointing to the one website.

    I want domain2.com to redirect to a file if you go to domain2.com.

    i.e. www.domain2.com redirect to domain2.com/file.htm

    However, if someone comes into www.domain2.com/anything/, they shouldn't be redirected. "anything" is a number of different folders that are already created n the server.

    Domain1.com should not be affected at all, that shouldn't be redirected.

    I've tried a few things with mod_rewrite, but can't seem to get it going!

    Thanks in advance!
    Tom


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    You need to use a script as your DirectoryIndex, and check the HTTP_HOST in that. For PHP, it would be something like:

    [php]if (preg_match('/^(www\.)?domain2\.com$/', $_SERVER)) {
    header('Location: file.htm');
    } else {
    // Default action for domain1.com
    }[/php]


  • Registered Users, Registered Users 2 Posts: 706 ✭✭✭DJB


    I agree with Ken. If you're on a windows server, the asp code would look like:

    <%
    if instr(request.servervariables("HTTP_HOST"),"domain2.com") > 0 then
    response.redirect("somefile.htm")
    end if
    'normal page gets processed if it's domain1.com
    %>


  • Registered Users, Registered Users 2 Posts: 1,452 ✭✭✭tomED


    Ok sorry - I left out an important piece of information (Told you my brain was on go slow)

    The sub directories (i.e. domain2.com/whatever/) do an fread of the main file (i.e. index.php) - which means using script like this isn't possible.

    Unless, you can write me more code to check that if they are in a directory, don't redirect? :)


Advertisement