logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: How do I redirect a subdomain to a specific page?
Author
flatcircle



Joined: 27 Jun 2006
Posts: 79

PostPosted: Fri 09 Feb '07 10:09    Post subject: How do I redirect a subdomain to a specific page? Reply with quote

How do I redirect a subdomain to a specific page?

Seems simple but can't figure it out Sad
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

PostPosted: Fri 09 Feb '07 11:32    Post subject: Reply with quote

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

PostPosted: Fri 09 Feb '07 16:40    Post subject: Reply with quote

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

PostPosted: Fri 09 Feb '07 16:58    Post subject: Reply with quote

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

PostPosted: Mon 19 Feb '07 1:30    Post subject: Reply with quote

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


Reply to topic   Topic: How do I redirect a subdomain to a specific page? View previous topic :: View next topic
Post new topic   Forum Index -> Apache