1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Subdomain alias

Discussion in 'Plesk for Linux - 8.x and Older' started by PavelIvanov, Jul 24, 2005.

  1. PavelIvanov

    PavelIvanov Guest

    Hello everyone,

    I need to create an alias for subdomain.domain.com so it pint to www.domain.com in Plesk
    Can anyone please post the exact instructions to add to vhost.conf and tell me to which file to add it to domain.com/conf/vhost.conf or subdomains/<subdomain-name>/conf/vhost.conf ?

    Best Regards,
  2. jamesyeeoc

    jamesyeeoc Guest

    The easiest way to do this is to add a wildcard DNS entry for the domain. Then anything.domain.com (even if you have not defined the sub) will go to the domain's document root.

    This is good for if someone mis-spells a subdomain URL, then they get your home page instead of PageNotFound (as long as they don't mis-spell the domain.com part)
  3. PavelIvanov

    PavelIvanov Guest

    That will work but not in my case

    I need it the way so email.domain.com show the mail.domain1.com index page

    Any suggestions ?

  4. jamesyeeoc

    jamesyeeoc Guest

    Ok, that's a slight bit different than your original posted stated....

    Here is what you can put into your main domain's vhost.conf file (/home/httpd/vhosts/domain.com/conf/vhost.conf)

    What this does is a simple test to make sure it is 'email.domain.com' being asked for, and not error page, then rewrites the URL to redirect to the hard coded FQDN specified.

    Further processing is then passed to domain1.com whether it is a locally hosted domain or somewhere else.

    Note: this sample is provided 'as-is' with no warranty implied or otherwise stipulated. If your exact requirements are different than posted, then the use of this sample may or may not do what you need. We can only work with the condition info you provide. :)
  5. PavelIvanov

    PavelIvanov Guest

    Ok i will provide you with more info :)

    Before i try your instructions i have tried this at /home/httpd/vhosts/domain.com/conf/vhost.conf

    ServerAlias email.domain1.com email.domain2.com email.domain3.us
    <Directory /home/httpd/vhosts/domain.com/subdomains/mail/httpdocs>
    php_admin_value safe_mode 0
    php_admin_value open_basedir "/home/httpd/vhosts/domain1/subdomains/mail/httpdocs/:/"

    But it didnt made the mail.domain.com as an alias for
    email.domain1.com email.domain2.com email.domain3.us

    To make things clear i simply need this
    I want anyone who visit these subdomains
    email.domain1.com email.domain2.com email.domain3.us

    to see the same as if they were visiting domain.com

    Can you please post again based on that information ?

  6. jamesyeeoc

    jamesyeeoc Guest

    Well of course not, you did not specify that in the 2nd post,
    which is why I put my disclaimer at the bottom (been thru this too many times).
    So when someone browses to email.domain1.com or email.domain2.com or email.domain3.us, you want them to go
    to mail.domain.com Is this correct??

    I am assuming that all 3 domains are already setup for hosting on your server and are already properly configured and operating. If not, then you will have to do that first!

    The http://mail.domain.com in the last line can be whatever FQDN you wish them to be redirected to. I used mail.domain.com from your original posting.

    I shouldn't have to mention this, but I will anyways: Since the vhost.conf files are domain specific, you will need to replicate this into each vhost.conf file for each of the domains: domain1.com, domain2.com, domain3.us. In each of the files, you can remove the 2 sections which are not for the particular domain. I hope that explanation was not too confusing.

    In other words, you will have 3 slightly different vhost.conf files, one in each of:


    You would NOT put all that into a single vhost.conf in /home/httpd/vhosts/domain.com/conf
  7. jamesyeeoc

    jamesyeeoc Guest

    Sorry, but PM is too limited, so I'll reply here in topic:
    Yes. When you browse to a URL, say http://email.domain1.com, apache will look at the config files for 'domain1.com', so if you want to redirect from domain1.com to another domain, the rewrite rules must be put in the conf file for domain1.com.

    You cannot put it into the 'destination' domain's conf file, since that won't get looked at by apache until after the redirect is done from the other domain.

    You don't want the periods, replace them with a single space. I just put that in my example to show '.....' to be 'whatever'. If you want certain custom config items to affect the ~/email subdomain directories, you would put them between the <Directory ...> statements. Without knowing exactly what you need, want, or are trying to do, I cannot comment on if the exact statements you put are 'correct' or not.

    The <Directory > and </Directory> section is not required for the rewrite rules to operate. All I have been concerned with is trying to get your rewrite to work.

    Not so many as there used to be, but more than 'none'. Some people may get frustrated with the lack of detail in people's posts, or having to post over and over because the real 'conditions' keep changing with each post (sound familiar?) In the future, please try to be clear in the initial post as to what you are really trying to accomplish. It will cut down on the time to resolution.
  8. gerhard@

    gerhard@ Guest

    Hi James ;), I've been trying a similar thing but it doesn't work as desired. This is how my vhost.conf looks like:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteMap lowercase int
    ServerAlias sub
    %{HTTP_HOST} ^sub.thisdomain.tld$
    RewriteCond %{REQUEST_URI} !error_docs
    ^/(.*) http://sub.otherdomain.tld/dir$1 [L,R]
    The problem is that the whole URL changes to http://sub.otherdomain.tld/dir rather than staying sub.thisdomain.tld. Any ideas?

  9. jamesyeeoc

    jamesyeeoc Guest

    Yes, this is because the line:

    RewriteRule ^/(.*) http://sub.otherdomain.tld/dir$1 [L,R]

    Does a Redirect to the new URL, that's why the URL gets changed.

    If I understand correctly, you just want to redirect them to a different domain's sub-directory but keep the URL the same?

    Are both domains on the same Plesk server and owned by the same client? I guess I have some research to do, I've never tried cross domain rewriting :)
  10. gerhard@

    gerhard@ Guest

    Heck James, that was quick ;).

    Well, I tried with CNAME, but it won't work. What I basically need is domain aliasing. Visitors thinking that they are on sub.thisdomain.tld but them actually being on sub.otherdomain.tld (like mirroring). Unfortunately, the sites are hosted on separate servers. Otherwise, it would have been pretty straightfw ;).

    I was thinking that Apache would handle requests "behind" the browser, thus passing data between the 2 servers & using rewrites to keep the desired URL and making the visitor think he's on sub.thisdomain.com.
  11. jamesyeeoc

    jamesyeeoc Guest

    (Just call me Speedy Gonzalez, love that little mouse!)

    Hmm, the domains being on different servers would pose a more complicated problem. But for future reference, here is what you could do if they were on the same server:

    Same server, cross domain redirection
    # vhost.conf for http://sub.thisdomain.tld
    # File: /home/httpd/vhosts/thisdomain.tld/conf/vhost.conf
    # test for Gerhard to redirect/rewrite from http://sub.thisdomain.tld to http://sub.otherdomain.tld/dir/
    # Need change
    # from ~/vhosts/thisdomain.tld/subdomains/sub/httpdocs/index.html
    # to ~/vhosts/otherdomain.tld/subdomains/sub/httpdocs/dir/index.html
    # This will be a simple 'close' example, maybe not the *exact* you need, but should help get you
    # on your way to the finished product. I know there are still some minor bugs with this code
    # but it's just a simple example!
    <IfModule mod_rewrite.c>
    RewriteEngine on

    ServerAlias sub.thisdomain.tld

    # Rewrite sub.thisdomain.tld/index.html to sub.otherdomain.tld/dir/index.html
    AliasMatch /index(.*) /home/httpd/vhosts/otherdomain.tld/subdomains/sub/httpdocs/dir/index.html

    ####### End of this section #######

    Separate servers, domain redirection
    File: /home/httpd/vhosts/thisdomain.tld/subdomains/sub/conf/vhost.conf

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteMap lowercase int:tolower
    ServerAlias sub.thisdomain.tld
    RewriteCond %{HTTP_HOST} ^sub.thisdomain.tld$
    RewriteCond %{REQUEST_URI} !^/subdomains/sub/
    RewriteCond %{REQUEST_URI} !error_docs
    RewriteRule (.*) http://sub.otherdomain.tld/dir/$1 [L,P]

    Notice that we are using a P (proxy) instead of R (redirect).
    I tested this browsing to sub.mytestdomain.com and it redirected to othersub.otherdomain.com/somedir my browser still showed 'sub.mytestdomain.com'.

    However as soon as you click on a link at the new site, the otherdomain apache (of course) changes the browser URL to reflect the new 'otherdomain.tld'. I suppose you could then write more rewrite code on the 'otherdomain.tld' server to take care of it on that end. (but that's a whole different lesson, class is dismissed)

    The user's browser still shows the original URL without change.
  12. gerhard@

    gerhard@ Guest

    Tried your last suggestion but now it won't do anything. Just loads up Plesk's default page... :(

    I was looking around and noticed on DynDNS site the same thing that I am trying to do: domain cloaking. Still, have no idea how to go around it.

    From all the things that I tried, re-directing worked but it also changes the URL (something I do not want). Since I have a nice and shiny box with SSH access, I can have a play with named or any other process that you think might help me achieve my goal.

    Cheers James, your help is appreciated ;).
  13. jamesyeeoc

    jamesyeeoc Guest

    After you made those changes in vhost.conf, did you run these 2 commands:

    /usr/local/psa/admin/bin/websrvmng -u --vhost-name=thisdomain.tld

    service httpd restart
  14. gerhard@

    gerhard@ Guest

    You're a genius James! It flippin' worked! Cheers bud ;).

    So basically all those fancy domain cloaking services are clever implementations of mod_rewrite, right?

    Spankingly brilliant! :p