Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

domain2.com forwards to domain1.com/subdirectory

Codes here !

Moderators: macek, egami, gesf

domain2.com forwards to domain1.com/subdirectory

Postby tomb » Sun Jul 06, 2003 8:49 pm

Hi. I have 2 domains. domain2.com points to domain1.com

Does anyone know of a script that can check if domain2.com is typed in the address and if it is then forward to domain1.com/subdirectory

That would be terrific! Thanks. :)
tomb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Jul 06, 2003 7:59 pm

Postby Joel » Sun Jul 06, 2003 11:25 pm

I'm not completely sure what you mean, or if this is the right forum. But this code, will make someone who goes to http://www.domain2.com be taken to http://www.domain1.com/sub

You have you have this before any coding is output to the browser.

Code: Select all
<?php
header("Location: http://www.domain1.com/subdirectory");
?>
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby tomb » Mon Jul 07, 2003 12:05 am

Yeah I realised it was the wrong forum right after I posted. I was hoping the mods would move it for me. :oops:

That's not quite what I was after since you could only use this if you had an account on domain2.com. I need something in the header of domain2.com/index.php.
The code would look something like this:

if (location = domain2.com){
forward to domain1.com/sub
}

This would go in the header of domain1.com/index.php
tomb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Jul 06, 2003 7:59 pm

Postby Joel » Mon Jul 07, 2003 12:12 am

I don't quite know what you mean. This is what I think:

The domain2.com is a referring domain name, that isnt set up with DNS information.

In this case, I think the code would be something like this...

if ($_SERVER['HTTP_REFERER'] == "http://www.domain2.com") {
header("Location: http://www.domain1.com/sub");
}
Last edited by Joel on Mon Jul 07, 2003 12:44 am, edited 2 times in total.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby tomb » Mon Jul 07, 2003 12:20 am

Do you have control over index.php of domain2.com?

No because domain2.com points directly to domain1.com. There's no index.php in domain2.com so all code must be put in domain1.com/index.php.
tomb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Jul 06, 2003 7:59 pm

Postby tomb » Mon Jul 07, 2003 12:26 am

This is an ASP version of what I'm after:
Code: Select all
    '**************************************
    ' Name: Multi Domain Redirect
    ' Description:If you have multiple domai
    '     n names pointing to the same web site, t
    '     his code will allow you to redirect the
    '     user to a subdirectory based on the web
    '     address then type in the browser.
    ' By: Glenn C.
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6349&lngWId=4    'for details.    '**************************************
   
    <%@ Language=VBScript %>
    <%
    ' Set up your variables
    Dim sURL, sPath
    ' Get the domain name typed in the brows
    '     er.
    sURL = Request.ServerVariables("HTTP_HOST")
    ' Get the rest of the path after the dom
    '     ain name.
    sPath = Request.ServerVariables("PATH_INFO")
    ' Based on the domain name, redirect the
    '     user
    ' to the correct directory and attach th
    '     e rest
    ' of the path.
    Select Case sURL
       Case "www.maindomain.com", "maindomain.com"
          ' Ignore...this is the current site.
       Case "www.domain2.com", "domain2.com"
          ' redirect To the "domain2" directory
    Response.Redirect "domain2" & sPath
       Case "www.domain2.net", "domain2.net"
    ' redirect to the "domain2net" directory
    '     
          Response.Redirect "domain2net" & sPath
    End Select
    %>
tomb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Jul 06, 2003 7:59 pm

Postby Joel » Mon Jul 07, 2003 12:38 am

I edited my last post, that code should work. I didnt realise what you said at first.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby tomb » Mon Jul 07, 2003 12:44 am

Thanks Joel. I'll try it out tomorrow when my domain's up and running. Cheers.
tomb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Jul 06, 2003 7:59 pm

Postby tomb » Tue Jul 08, 2003 6:02 am

Thanks. This is what I ended up using for anyone interested:

Code: Select all
<?php
if ($_SERVER['SERVER_NAME'] == "www.domain2.com" || $_SERVER['SERVER_NAME'] == "domain2.com") {
   header("Location: http://www.domain2.com/sub");
}
?>
tomb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Jul 06, 2003 7:59 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.