WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-10-2003, 05:40 PM
WebProWorld Member
 

Join Date: Jul 2003
Location: Southern California
Posts: 75
CLBridges RepRank 0
Default Redirecting "pointed" domains based on domain name

Can the htaccess file redirect "pointed" domains to a specific URL based on the domain name requested? (Gosh, that doesn't make any sense to me either!)

For instance.. my main site is www.maindomain.com and I have www.subdomain1.com and www.subdomain2.com both pointed to the same IP address as www.maindomain.com. Without being redirected, requests for all 3 domains reach the same index.htm page in my root directory.

Using htaccess, is it possible to redirect
requests for www.maindomain.com to /index.htm, and
requests for www.subdomain1.com to /subdir1/index.htm, and
requests for www.subdomain2.com to /subdir2/index.htm,

Or can only the relative path be used for the URL being directed?

I'm sorry.. I wish I knew the technical terms for all this.. :(

All help is appreciated.

Thanx! Carrie**
Reply With Quote
  #2 (permalink)  
Old 11-11-2003, 04:40 PM
WebProWorld Member
 

Join Date: Aug 2003
Location: Canada
Posts: 30
AlexBel RepRank 0
Default Re: Redirecting "pointed" domains based on domain

Hi Carrie,
If you use Apache, you can write statement DocumentRoot for each VirtualHost in httpd.conf
For expample:
Code:
NameVirtualHost www.subdomain1.com
<VirtualHost www.subdomain1.com>
    DocumentRoot "your_path/subdir1"
    ServerName www.subdomain1.com
    ErrorLog logs/web-error.log
    CustomLog logs/web-access.log common
    ScriptAlias /cgi-bin/ "your_path/cgi-bin/"
</VirtualHost>
__________________
<-- AlexBel -->
Reply With Quote
  #3 (permalink)  
Old 11-12-2003, 11:43 AM
WebProWorld Member
 

Join Date: Jul 2003
Location: Southern California
Posts: 75
CLBridges RepRank 0
Default Re: Redirecting "pointed" domains based on domain

Quote:
Originally Posted by AlexBel
If you use Apache, you can write statement DocumentRoot for each VirtualHost in httpd.conf
Hi Alex.. I was afraid of that :( I don't have access to the httpd.conf file. I knew it could be done somehow because a site I used to maintain a long time ago was set up that way. I've already asked our host if it could be done, but they told me no. Probably just trying to get more money outta me!

I'll pass the code you provided along to their tech support department with a copy of my original request and their reply asking "Why NOT?"

Thank You for the info!

Carrie**
Reply With Quote
  #4 (permalink)  
Old 11-13-2003, 06:02 PM
Egg Egg is offline
WebProWorld New Member
 

Join Date: Jul 2003
Location: Victoria BC Canada
Posts: 19
Egg RepRank 0
Default .htaccess Different Dirs with Different Domains

I've tried the same idea, and never got it exactly with .htaccess ( so I handled it with PHP )
The biggest problem I found, was that it Visibly redirected ( ie: the addy in the address bar changed ) instead of doing it 'silently / invisibly'

Anyways, I think you may have to use MODREWRITE in the long run, here is the Apache page for it:
http://httpd.apache.org/docs/misc/rewriteguide.html

The basic idea will be
1) it checks the domain name ( HTTP_HOST )
2) it redirects to the subdir.

I hope this helps start you off, but this topic could really use more expansion on it by someone with some modrewrite experience!

Good luck!
__________________
<a href=http://www.wackywillysweb.com?d=wpw>Anime, Cool Lighters, Hello Kitty</a>
<a href=http://www.pacificrimwholesale.com>Wholesale Kid's Clothing
Reply With Quote
  #5 (permalink)  
Old 11-13-2003, 06:31 PM
WebProWorld Member
 

Join Date: Aug 2003
Location: Canada
Posts: 30
AlexBel RepRank 0
Default Re: .htaccess Different Dirs with Different Domains

Quote:
Originally Posted by Darryl of DlDesign
Anyways, I think you may have to use MODREWRITE in the long run, here is the Apache page for it:
http://httpd.apache.org/docs/misc/rewriteguide.html

The basic idea will be
1) it checks the domain name ( HTTP_HOST )
2) it redirects to the subdir.
Yes, Why not?
__________________
<-- AlexBel -->
Reply With Quote
  #6 (permalink)  
Old 11-22-2003, 10:55 AM
williamjay's Avatar
WebProWorld New Member
 

Join Date: Sep 2003
Location: Prince Edward Island, Canada
Posts: 15
williamjay RepRank 0
Default Redirect

How about??

RedirectPermanent www.subdomain1.com /subdir1/
RedirectPermanent www.subdomain2.com /subdir2/

William
Reply With Quote
  #7 (permalink)  
Old 11-23-2003, 12:03 AM
WebProWorld New Member
 

Join Date: Aug 2003
Location: N. Texas
Posts: 5
jdMorgan RepRank 0
Default

Carrie,

The following code may be useful, although your requirements description had some ambiguities in it. I'm not sure you really want to redirect *all* requests for *any file* in a particular subdomain to the index.html file in the corresponding subdirectory, so here's what this code actually does; you can tweak it as needed:

If www.maindomain.com/<whatever> or maindomain.com<whatever> do nothing - serve the requested file.

If www.subdomain1.com/<whatever.file> or subdomain1.com/<whatever.file>, redirect silently to /subdomain1/<whatever.file>

If www.subdomain2.com/<whatever.file> or subdomain2.com/<whatever.file>, redirect silently to /subdomain2/<whatever.file>
Code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST}  !^(www\.)?maindomain\.com
RewriteCond %{HTTP_HOST}  ^(www\.)?([^\.]*)\.com
RewriteRule ^(.*)$ /%2/$1 [L]
The Options line may not be needed if your server configuration already enables FollowSymLinks -- try it with and without.

Similarly, RewriteEngine on is only needed once in your .htaccess file -- before any rewrite directives.

Jim
Reply With Quote
  #8 (permalink)  
Old 11-24-2003, 07:48 PM
Egg Egg is offline
WebProWorld New Member
 

Join Date: Jul 2003
Location: Victoria BC Canada
Posts: 19
Egg RepRank 0
Default Thanks JdMorgan!

The 'silent redirection' aspect can be very important to the feeling of your visitors 'safety, and being in control' thank you for that elusive modrewrite code!

As for you Carrie, if you wanted the simple, non-invisible PHP code redirection, you make a .php file that goes like this:

<?php
// First step, decide using the domain name which
// directory you want to redirect to

$redirtothisfile="default_index.html";

if ($HTTP_SERVER_VARS['HTTP_HOST']==="dogs.com")
{$redirtothisfile="/dogs/dogindex.html";}

if ($HTTP_SERVER_VARS['HTTP_HOST'] ==="purbreddogs.com")
{$redirtothisfile="/dogs/purbreadindex.html";}

if ($HTTP_SERVER_VARS['HTTP_HOST'] ==="cats.com")
{$redirtothisfile="/cats/index.html";}

if (SOME_OTHER_FACTOR) {$redirtothisfile="SOMEFILE"}

// 2) now add the 'HTML HEADER' redirection
// see the PHP manual for header() here:
// http://www.php.net/manual/en/function.header.php

header("Location: $redirtothisfile");
die;
?>

And that's it! The browser will redirect with this, the script will end, and you'll see the new page etc. . .
__________________
<a href=http://www.wackywillysweb.com?d=wpw>Anime, Cool Lighters, Hello Kitty</a>
<a href=http://www.pacificrimwholesale.com>Wholesale Kid's Clothing
Reply With Quote
  #9 (permalink)  
Old 11-26-2003, 08:24 AM
WebProWorld Member
 

Join Date: Jul 2003
Location: Southern California
Posts: 75
CLBridges RepRank 0
Default invisibility

Yes, invisibility is an important part of what I am hoping to achieve. Everyone has been very helpful.. thank you! I'm still waiting.. er, "corresponding" with them about it.. (read: asking WHY NOT??)
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0