Evil Glint Posted January 26, 2011 Share Posted January 26, 2011 A while back, I asked about changing the default website location for Mac OS X users from "http://site.com/~user/" to "http://user.site.com/". From "http://site.com/~user/" to "http://user.site.com/" I now have my answer, but the topic is too old to bump. If anyone else is looking for this information: In httpd.conf, make sure these lines are commented out, or do not exist: LoadModule userdir_module libexec/httpd/mod_userdir.so AddModule mod_userdir.c Make sure these lines exist, and are not commented out: LoadModule vhost_alias_module libexec/httpd/mod_vhost_alias.so AddModule mod_vhost_alias.c UseCanonicalName On Add a virtual host container: # User Sites <VirtualHost *:80> UseCanonicalName Off VirtualDocumentRoot /Users/%-2/Sites </VirtualHost> When using virtual hosts, the main website becomes inaccessible. To remedy this, we create a second virtual host, that mimics the main web server. # Main Website: <VirtualHost *:80> DocumentRoot /Library/WebServer/Documents ServerName domain.tk ServerAlias 10.0.0.2 localhost 127.0.0.1 </VirtualHost> Replace: "domain.tk" with the domain of your site "10.0.0.2" with your LAN IP address "127.0.0.1" with your internal IP address (usually "127.0.0.1") Note: The user sites virtual host MUST be at the TOP of your list of virtual hosts, or it WILL NOT WORK! All domain / sub-domain names that are not specifically assigned will be sent to the first virtual host, so if the user sites virtual host is not the first on the list, IT WILL NEVER BE USED. Also, if you don't have wild-card DNS, you will need to make a record of each user's sub-domain with your DNS provider. If you want to avoid sending 404 pages to people who access your server from URLs that you don't anticipate (such as "http:// www .domain.tk/" if you don't use "www.", or http:// domain.tk/ if you do use "www.", or other extra sub-domains, if you have wild-card DNS), add this line outside the virtual hosts: ErrorDocument 404 http://domain.tk/ Change "domain.tk" to your preferred domain. To prevent this from redirecting 404 errors on your main / user sites, override it by adding this to both of your virtual host containers (and any other virtual hosts you may have): ErrorDocument 404 /404.php Change to match the location of your 404 page. Man, that was long winded. Time to breath. Some of that info was discovered by trial and error, but I must give credit to http://web-magician.blogspot.com/2007/07/dynamic-virtual-host-with-apache.html for the final piece of the puzzle. It has a far more understandable guide to dynamic virtual hosts than the Apache manual. Quote Link to comment https://forums.phpfreaks.com/topic/225797-solution-from-httpsitecom~user-to-httpusersitecom/ Share on other sites More sharing options...
Evil Glint Posted January 26, 2011 Author Share Posted January 26, 2011 I made a mistake: If you add this code to the "user sites" virtual host, it ruins the whole redirect: ErrorDocument 404 /404.php Put the code in the .htaccess file (if it is enabled) for better results. Quote Link to comment https://forums.phpfreaks.com/topic/225797-solution-from-httpsitecom~user-to-httpusersitecom/#findComment-1165730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.