The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Dynamically rewrite mod_userdir URLs (stagingdomain.com/~username) to username.stagingdomain.com

Discussion in 'General Discussion' started by kristofferR, Feb 25, 2013.

  1. kristofferR

    kristofferR Member

    Joined:
    Oct 20, 2012
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I run a small web host with automatic installation of Wordpress at signup. When a client signs up, Wordpress is automatically installed using a script running after CPanel has created the user.

    All the customers get their own .com/.net/.org domain at signup, however since domain propagation takes some time (and I advertise that their sites are installed within 60 seconds after signup), I need to provide a temporary URL in the meantime.

    I'm using the Apache module mod_userdir for that, and it works okay, except for one thing. The resulting URLs are formatted like this: StagingDomain.com/~username. The tilde sign ( ~ ) is the problem.

    It confuses both the customers (who often don't know how to type the ~ sign) and Wordpress. In order for Wordpress to work properly I have to resort to some stupid hacks/workarounds that must be uninstalled when the domain propagation is done and the site is ready for the domain.

    It would be great to be able to provide the customers with their own subdomain instead.

    The right way to do this would, as far as I have understood, be to use mod_vhost_alias to map virtual subdomains to the mod_userdir folders.

    However, I simply can't wrap my head around how to do it. I've tried a lot of things, but there are simply too many different factors in play that I don't understand sufficiently to get it to work.

    I hope you guys and girls can help me with that.

    Current setup

    Distro: CentOS 6.3 with WHM 11.36.0 (build 9) (fully updated)
    Apache: 2.4.3
    PHP: 5.4.11 (with SuPHP)

    CustomerDomain.com - the domain the customer registered at signup and that will be used after domain has propagated
    StagingDomain.com - a domain I own. I want the Linux username of the customer, currently used in the "~username", to be a subdomain to the domain

    The files are loaded/executed from /home/customeruser/public_html/

    Virtualhost for CustomerDomain.com:
    Code:
    <VirtualHost serverip:80>
        ServerName customerdomain.com
        ServerAlias www.customerdomain.com
        DocumentRoot /home/customeruser/public_html
        ServerAdmin webmaster@customerdomain.com
        UseCanonicalName Off
        Options -ExecCGI -Includes
        RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
        CustomLog /usr/local/apache/domlogs/customerdomain.com combined
        CustomLog /usr/local/apache/domlogs/customerdomain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
        ## User customeruser # Needed for Cpanel::ApacheConf
        UserDir disabled
        UserDir enabled customeruser 
    
        # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
        # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
        # the user's .htaccess file.  For more information, please read:
        #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
        <IfModule mod_include.c>
            <Directory "/home/customeruser/public_html">
                SSILegacyExprParser On
            </Directory>
        </IfModule>
    
        <IfModule mod_suphp.c>
            suPHP_UserGroup customeruser customeruser
        </IfModule>
        <IfModule !mod_disable_suexec.c>
            <IfModule !mod_ruid2.c>
                SuexecUserGroup customeruser customeruser
            </IfModule>
        </IfModule>
        <IfModule mod_ruid2.c>
            RUidGid customeruser customeruser
        </IfModule>
    
    
        # To customize this VirtualHost use an include file at the following location
        # Include "/usr/local/apache/conf/userdata/std/2/customeruser/customeruser.no/*.conf"
    
    </VirtualHost>

    Virtualhost for StagingDomain.com
    Code:
    <VirtualHost serverip:80>
        ServerName stagingdomain.com
        ServerAlias www.stagingdomain.com
        DocumentRoot /home/staginguser/public_html
        ServerAdmin webmaster@stagingdomain.com
        UseCanonicalName Off
        CustomLog /usr/local/apache/domlogs/stagingdomain.com combined
        CustomLog /usr/local/apache/domlogs/stagingdomain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
        ## User staginguser # Needed for Cpanel::ApacheConf
    
    UserDir enabled
    
    # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
    # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
    # the user's .htaccess file.  For more information, please read:
    #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
    <IfModule mod_include.c>
        <Directory "/home/staginguser/public_html">
            SSILegacyExprParser On
        </Directory>
    </IfModule>
    
    <IfModule mod_suphp.c>
        suPHP_UserGroup staginguser staginguser
    </IfModule>
    <IfModule !mod_disable_suexec.c>
        <IfModule !mod_ruid2.c>
            SuexecUserGroup staginguser staginguser
        </IfModule>
    </IfModule>
    <IfModule mod_ruid2.c>
        RUidGid staginguser staginguser
    </IfModule>
    ScriptAlias /cgi-bin/ /home/staginguser/public_html/cgi-bin/
    
    
    # To customize this VirtualHost use an include file at the following location
    # Include "/usr/local/apache/conf/userdata/std/2/staginguser/staginguser.com/*.conf"
    
    </VirtualHost>

    The resulting temporary (mod_userdir) url for the two Virtualhosts above is stagingdomain.com/~customeruser. It works, but it is messy, cumbersome, and it looks really unprofessional.

    customeruser.stagingdomain.com would be a much better option as a temporary url for my clients. I know it's possible, I just can't figure out how to do it.
     
Loading...

Share This Page