PHP redirect
Moderator: General Moderators
PHP redirect
OK...
I have 2 domains, one aliased to the other, both pull up the same content, and the urls stay the same, I want to have one url redirect to the other...
ie:
http://www.domain.com
http://www.domain2.com
So, if http://www.domain2.com is entered, it redirects to http://www.domain.com
Any help much appreciated!
Revised: same index file and I do not have access to the .htaccess file
I have 2 domains, one aliased to the other, both pull up the same content, and the urls stay the same, I want to have one url redirect to the other...
ie:
http://www.domain.com
http://www.domain2.com
So, if http://www.domain2.com is entered, it redirects to http://www.domain.com
Any help much appreciated!
Revised: same index file and I do not have access to the .htaccess file
Last edited by borris on Wed Oct 23, 2002 6:05 pm, edited 1 time in total.
on the index.html of http://www.domain2.com (or whatever is the default file) put:
Code: Select all
<?php
header("Location: http://www.domain.com/");
?>- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
using an index.php file won't work because both domains access the same index.php file. doing that would result in a nasty loop.
if you can use .htaccess you might try this:
i haven't tested this but according to the apahce manual it should work
if you can use .htaccess you might try this:
Code: Select all
RewriteCond %{HTTP_HOST} ^*domain2.com
RewriteRule ^(.*) /$1 їR]- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
put this at the top of your index.php to check which domain is being used and then redirect to the preferred one if the secondary one was used.
the regular expression could use some work but it should still work.
Code: Select all
<?php
if (preg_match("/domain2/", $_SERVERї'HTTP_HOST']) {
header("Location: http://www.domain.com");
}
?>change that code to:
It works now... 
Code: Select all
<?php
if (preg_match("/domain2/", $_SERVERї'HTTP_HOST'])) {
header("Location: http://www.domain.com");
}
?>- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact: