homepage Welcome to WebmasterWorld Guest from 54.211.219.178
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Dynamically rewrite mod userdir URLs (site.com/~user) to user.site.com
Dynamically rewrite mod_userdir URLs (site.com/~user) to user.site.com
kristofferR




msg:4548716
 4:48 pm on Feb 25, 2013 (gmt 0)

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 [httpd.apache.org] 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 (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:
<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 ."

UserDir disabled
UserDir enabled customeruser

<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>
</VirtualHost>



Virtualhost for StagingDomain.com
<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 ."

UserDir enabled

<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/

</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.

 

phranque




msg:4548851
 12:20 am on Feb 26, 2013 (gmt 0)

welcome to WebmasterWorld, kristofferR!

you could configure your DNS and web server for wildcard subdomains and use mod_rewrite directives for doing an external redirect from subdirectories to subdomains and an internal rewrite from subdomains to subdirectories.

however the customer subdomains on your staging domain should probably be protected by basic HTTP authentication to avoid public access to staged content and non-canonical url-related issues.

kristofferR




msg:4551339
 12:36 pm on Mar 5, 2013 (gmt 0)

Thanks! How would this work with suPHP? When I tryed using mod_rewrite I just got a lot of suPHP releated errors.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved