Author |
|
flatcircle
Joined: 27 Jun 2006 Posts: 79
|
Posted: Fri 09 Feb '07 10:09 Post subject: How do I redirect a subdomain to a specific page? |
|
|
How do I redirect a subdomain to a specific page?
Seems simple but can't figure it out
Do I have to do this at DNS level or on my Apache server (using modrewrite or something)?
I have read a lot about modrewrite but I'm not sure I have to use this in this case.
I want to
sub.domain.com
redirect to
http://www.anotherdomain.com/a_specific_page.htm
Possible?
Regards. |
|
Back to top |
|
bentogoa
Joined: 09 Feb 2007 Posts: 66 Location: GOA
|
Posted: Fri 09 Feb '07 11:32 Post subject: |
|
|
Code: | <?php
if ($_SERVER['HTTP_HOST'] == "YOUR SUBDOMAIN NAME")
{
header("Location: http:// YOUR NEW PAGE URL");
exit;
}
?> |
Bento Fernandes
http://www.goanwap.com
admin at goanwap dot com |
|
Back to top |
|
flatcircle
Joined: 27 Jun 2006 Posts: 79
|
Posted: Fri 09 Feb '07 16:40 Post subject: |
|
|
thanks!
So I suppose I have to create some webspace for this subdomain and place this index.php in this folder.
I thought it was possible to redirect without even create webspace for this 'dummy' domainname. Can this be done without creating this 'dummy' site? |
|
Back to top |
|
bentogoa
Joined: 09 Feb 2007 Posts: 66 Location: GOA
|
Posted: Fri 09 Feb '07 16:58 Post subject: |
|
|
Set the dns A records so that "YOUR SUB DOMAIN" ip is same as the domain.
the in the index.php file of your domain (on top) enter this.
If the user has open the site sub.domain.com then the user willbe redirected, if he opens the site typing www.domain.com he will be able to access the site. |
|
Back to top |
|
FiDO
Joined: 18 Feb 2007 Posts: 1
|
Posted: Mon 19 Feb '07 1:30 Post subject: |
|
|
flatcircle wrote: | I thought it was possible to redirect without even create webspace for this 'dummy' domainname. Can this be done without creating this 'dummy' site? |
It can be done with mod_rewrite.
Try this:
Code: |
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.domain.com$ [NC]
RewriteRule / http://www.anotherdomain.com/a_specific_page.htm [R]
|
Should help.
PS. you have to uncomment LoadModule rewrite_module modules/mod_rewrite.so to enable mod_rewrite. |
|
Back to top |
|