Subdomain Redirect


#1

I want to redirect a subdomain to a directory on the main domain. For example, sub.domain.com point to www.domain.com/dir but not have the sub.domain.com change to www.domain.com/dir on the redirect. The subdomain would act the same as if I was actually hosting the files in the subdomain.

I think I would be able to do this using VirtualHost and ServerAlias in Apache. Is it possible to accomplish this on DreamHost?


#2

This looks like an extension of your previous post. What became of that?
http://discussion.dreamhost.com/showflat.pl?Cat=0&Board=forum_troubleshooting&Number=114969

Here’s a similar recent thread:
http://discussion.dreamhost.com/showflat.pl?Cat=0&Board=forum_troubleshooting&Number=115016&page=&view=&sb=&o=&vc=1

I’m no htaccess guru, so that’s about all I’ve got. Hopefully Atropos7 will be along to see your request.

-Scott


#3

You are not asking for a redirect, and rewriting will not do what you want either. I don’t think you understand what those terms mean in the first place.

REDIRECT:

  1. Visitor types a URL into browser
  2. Browser attempts to fetch content for the URL
  3. Server tells browser to fetch a different URL instead
  4. Browser attempts to fetch content at the different URL
  5. Server gives browser the content

REWRITE:

  1. Visitor types a URL into browser
  2. Browser attempts to fetch content for the URL
  3. Server changes the value of the url-path (NOT THE HOSTNAME)
  4. Server gives browser the content

So as you can see, neither one will do what you want. A redirect will change the URL, and a rewrite cannot work with different hostnames (if you try a redirect is forced).

Close. The directive involved would be DocumentRoot

DreamHost calls it the “web directory” and you get to specify it either when adding the subdomain or when you “Edit” the subdomain from the “Manage Domains” panel. You cannot add ServerAlias directives.

Keep in mind the “web directory” is a filesystem path and not a url-path. This means that /home/username/domain.com/dir/ must exist in the filesystem.

:cool: openvein.org -//-


#4

When I see requests like this, I wonder if it’s just a matter of changing the web directory in the panel to a subdirectory of an existing domain. Will the panel allow such a shared resource?

And if that subdirectory relies on data from the parent directory, will the subdomain fail due to a now-nonexistent parent directory?

-Scott


#5

The panel will let you do it. Of course there will be side effects. For example requests might come in with different Host headers now. Also there may be configuration differences (ie, one hostname has extra web security and the other does not) and you might have issues with setting up the “.htaccess/WebDAV” panel and the like.

Well of course it would but its good to point that out. Obviously you would have to put the files in another directory and update the “web directory” for the subdomain.

And if you want to redirect visitors from http://domain/dir/ to http://dir.domain/ then you would have to use mod_rewrite directives or CGI scripts that check the Host header value.

:cool: openvein.org -//-


#6

The htaccess part of my previous topic did have to do with this. The CNAME part was a completely separate problem I had that I did end up solving using htaccess.

I did try changing the web directory of my subdomain from /home/username/sub.domain.com/ to /home/username/domain.com/dir/. That did not work. It just caused a bad_httpd_conf error to be displayed.

On a previous host I was on, they had a section in their panel called Virtual Sites which would take a subdomain and map it to a directory. When I moved to DreamHost I was trying to replicate that functionality.

Edit: Looking over the options in Manage Domain, it seems like I am not able to do what I’m trying to do. If the panel allowed me to mirror a subdomain to another domain’s directory then I would be able to achieve my goal. It seems the panel only allows mirrors of another domain but not of a domain’s directories.


#7

That error means the machine you connected to doesn’t have a virtual host entry for the subdomain. This will happen from time to time when you change the domain settings because DreamHost has to update the server configuration file and that is not an instantaneous process nor does it not have its glitches. It doesn’t mean it is impossible. I myself have done this before myself. If the error doesn’t go away I’m sure support could fix it for you.

For example http://zenphoto.openvein.org/ is a fully hosted subdomain, and its web directory is /home/username/openvein.org/zenphoto/ which means you see the same thing going to http://openvein.org/zenphoto/

It’s been clarified in the Wiki that the Mirror domain option simply adds a ServerAlias directive. The “Virtual Sites” option would have to have done the same thing as what I have suggested anyway! You forgot that DreamHost is using Apache HTTP Web Server and while a host can call things silly names like “web directory” and “virtual site” ultimately the web server software has its own processes that make things happen.

:cool: openvein.org -//-