.htaccess files are not processed on our servers for security reasons, as explained on DomTool/WhyNoHtaccess. See the examples below to learn how to use Apache features that are often controlled with .htaccess files.
1. The Default
The standard dom directive gives you a web site at www.yourdomain and yourdomain, pulling content from your ~/public_html directory.
dom "yourdomain" with end;
2. Extending the Default
You can tweak the configuration for your domain's www virtual host like this:
dom "yourdomain" where DocumentRoot = home "somewhere/else"; (* Serve static content from ~/somewhere/else. *) WWW = begin (* Here you can put any of the web configuration directives found in the sections below. *) end with (* ...and you can still put other domain configuration here. *) end
3. Simple Additional Web Sites
It's easy to add extra web sites to your domain when they just serve static content from subdirectories of your home directory:
dom "yourdomain" with simpleWeb "site1" "sites/site1"; (* This creates a web virtual host site1.yourdomain, serving content from ~/sites/site1. *) simpleWeb "site2" "sites/site2"; end
4. The Model T
Now we come to the web directive, which should be your main tool for creating additional virtual vhosts with custom configuration.
dom "yourdomain" with web "mywebhost" with (* This is a web host found at mywebhost.yourdomain. *) end; end;
Note that the web directive also adds the right DNS mapping for your virtual host. Never use web "www" within a dom directive. Instead, see the examples at the beginning of the Apache section. All of the directives demonstrated in the rest of the Apache section can be used between the begin and end demonstrated in that example.
5. The Do-It-Yourself
dom "yourdomain" with vhost "mywebhost" with end; end;
This one doesn't add any DNS mappings. You probably never want to use vhost instead of web.
6. The Top-Level Do-It-Yourself
The same can also be done to create a vhost accessible via http://yourdomain/.
dom "yourdomain" with vhostDefault with end; end;
7. Using a nonstandard web server
dom "yourdomain" with web "mywebhost" where WebPlaces = [web_place_default "fyodor"] with end; end;
8. Using SSL (HTTPS)
For this example, we assume that you've applied for and been granted permissions on the SSL certificate /etc/apache2/ssl/user/yourdomain.pem.
dom "yourdomain.com" where CreateWWW = false; with web "www" where SSL = use_cert "/etc/apache2/ssl/user/yourdomain.pem" with end; end;
9. Allowing non-secure & secure connection with same behaviour
If you want to enable ssl and force a redirect from http to https, the webSsl directive can handle this for you in most cases.
The example below is stripped of all extra settings on the "www" web directive. If you have any special settings, they should be copied as well.
dom "yourdomain.com" where CreateWWW = false; DocumentRoot = home "websites/yourdomain.com" with webSsl "www" (use_cert "/etc/apache2/ssl/user/yourdomain.pem") with end; end;
If you want to allow both http and https with the same configuration instead, you can set the ForceSSL environment variable to false.
dom "yourdomain.com" where CreateWWW = false; DocumentRoot = home "websites/yourdomain.com" with webSsl "www" (use_cert "/etc/apache2/ssl/user/yourdomain.pem") where ForceSSL = false with end; end;
10. Bucking all the trends
dom "yourdomain" with web "mywebhost" where DocumentRoot = home "private_html"; User = "me_web"; Group = "me_web"; SSL = use_cert "/home/me/mycert.pem" with end; end;
home "private_html" builds the full path to subdirectory private_html of your home directory.
11. Basic URL handling
dom "yourdomain" with web "mywebhost" with alias "/doc" "/usr/local/doc"; (* Serve all URIs beginning in /doc out of directory /usr/local/doc. Note that the second argument can't be just any old path. You need to have been granted permission to read from the path. You should have permission to read from any path within your home directory, as well as a few others, like /usr/share/moin. *) scriptAlias "/my-script" "/var/cgi/a-program"; (* Handle requests for /my-script by calling the CGI program /var/cgi/a-program. The example here uses a file, but scriptAlias directive can also alias CGI directories, as you'd expect: scriptAlias "/location/" "/directory/" *) errorDocument "404" "not_found.html"; (* Handle HTTP error code 404 by sending file not_found.html *) end; end;
12. Location-specific configuration
dom "yourdomain" with web "mywebhost" with location "/private" with errorDocument "404" "not_found_private.html"; end; (* When in the /private tree of URI-space, handle 404s with not_found_private.html *) directory "/usr/local/doc" with errorDocument "404" "not_found_doc.html"; end; (* When looking for a file in real directory /usr/local/doc, handle 404s with not_found_doc.html *) location "/cgi-bin" with options [execCGI]; cgiExtension "cgi" end; (* Any path like /cgi-bin/*.cgi should be executed as a CGI script. *) end; end;
13. Server aliases
dom "yourdomain" with web "mywebhost" with serverAliasHost "www2.yourdomain"; serverAliasHost "www.otherdomain"; (* www2.yourdomain and www.otherdomain are alternate names for this vhost *) serverAlias "www3"; (* Short form for an alternate name within the current domain *) serverAliasDefault; (* Make this virtual host answer to yourdomain, with no extra hostname needed in front. *) end; end;
Note that you must have Domtool configuration rights to all domains you name with serverAlias. See the example "Attack of the Model T Clones" for a more convenient way of duplicating all of a domain's configuration for one or more other domains.
14. Directory options
dom "yourdomain" with web "mywebhost" with options [execCGI, indexes]; (* Use exactly the Apache options execCGI and indexes by default for this vhost *) set_options [includesNOEXEC]; (* Add the option includesNOEXEC, leaving the others alone *) unset_options [followSymLinks]; (* Ask not to follow symbolic links. *) directoryIndex ["index.html", "index.php", "index.txt"]; (* When looking for the default file to serve for a directory, consider these possibilities in order *) action "image/gif" "/cgi-bin/images.cgi"; (* Run /cgi-bin/images.cgi to serve images *) addDefaultCharset "utf-8"; (* Use the UTF-8 character set by default *) location "/prefix" with forceType "text/plain"; (* Serve all files in this location as plain text *) forceTypeOff; (* Change our mind about that! *) (* All the other directives mentioned above can be used in locations, too, but forceType* _must_ be in a location. *) end; end; end;
15. Access control
dom "yourdomain" with web "mywebhost" with location "/loc1" with authType basic; (* Use HTTP basic authentication in this location *) authName "my domain"; (* Tell users that they're authenticating for "my domain" *) authUserFile "/etc/webusers"; (* Look up user/password information in /etc/webusers *) orderAllowDeny; (* Access is denied by default *) requireValidUser; (* Anyone providing a valid password is allowed *) denyFrom "badguys.evil.net"; (* However, anyone coming from this domain is banned *) denyFrom "1.2"; (* Also ban anyone with a 1.2.*.* IP address *) end; location "/loc2" with authType basic; authName "my other domain"; authUserFile "/etc/otherone"; denyFromAll; (* Deny everyone by default *) requireUser ["fred", "barney"]; (* Allow fred and barney in *) requireGroup ["prehistoric"]; (* Also require membership in the prehistoric group *) end; end; end
16. Fancy directory index generation
dom "yourdomain" with web "mywebhost" with addDescription "The planet Mars" "/web/pics/mars.gif"; (* Describe /web/pics/mars.gif as "The planet Mars" on index pages *) indexOptions [fancyIndexing, htmlTable, iconHeight 10, iconWidth 10]; (* Set some index-generation options *) headerName "header.html"; (* Include header.html at the start of a directory listing *) footerName "footer.html"; (* Include footer.html at the end of a directory listing *) end; end;
17. mod_rewrite
dom "yourdomain" with web "mywebhost" with rewriteRule "^(.+)\.php$" "$1.sml" []; (* Rewrite all URLs ending in .php to end in .sml *) rewriteRule "/gone.html" "http://somewhere.else/there.html" [redirectWith permanent]; (* Redirect /gone.html to http://somewhere.else/there.html, giving an HTTP code indicating a permanent relocation *) rewriteLogLevel 1; (* Turn on some more logging for rewrite debugging in /afs/hcoop.net/usr/$USER/apache/log/$NODE/www.yourdomain/error.log *) rewriteCond "%{REQUEST_FILENAME}" "-f" [cond_nocase, ornext]; (* An example of Apache's RewriteCond directive *) rewriteRule "/a.html" "http://a/b.html" [gone, chain, skip 5]; (* An example of specifying multiple rewrite flags *) end; end;
18. mod_proxy
dom "yourdomain" with web "mywebhost" with proxyPass "/mirror/foo/" "http://localhost:5555/"; (* Proxy path /mirror/foo/ to a local server with URL base http://localhost:5555/ *) proxyPassReverse "/mirror/foo/" "http://localhost:5555/"; (* Adjust Location and other HTTP headers appropriately for the above proxying *) proxyRewrite "/foo/(.*)$" "bar/$1" "http://localhost:5555" [qsappend]; (* Proxy path matching /foo/(.*)$ to http://localhost:5555/bar/$1, using mod_rewrite *) proxyPassReverse "/foo/" "http://localhost:5555/"; (* Adjust Location and other HTTP headers appropriately for the above proxying *) end; end;
19. SSI
dom "yourdomain" with web "mywebhost" with set_options [includesNOEXEC]; (* Or you could enable it for just some URIs: *) location "/ssi_world" with set_options [includesNOEXEC]; end; end; end;