Skip to content

Forward Slash

Earth3300 edited this page Jul 20, 2020 · 4 revisions

It is desirable from time to time to transparently place all the files in a domain in a directory. One immediate advantage of this is that incoming requests can be "shunted" to one directory or another, as needed. For example, if--after a few years of development--it is evident that a new website will need to be developed, but with a completely different underlying infrastructure, this can be done by placing all the files from Site 1.0 in a directory and all files from Site 2.0 in a second directory, as its peer. For example:

01. /  #root
02.   /site-1.0
03.   /site-2.0

This is typically not the default. The default is usually to place all files in the root, without consideration for having a clean backup ready, or being able to update by throwing a single switch. The following snippet configures the server to do this. Note that this can also (with modifications) be placed "higher" up in the server configuration, if the entire server configuration is accessible, such as in a virtual server, or on a local machine.

# Rewrite all requests to /foo
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{SERVER_NAME} www.foo.tld
  RewriteCond %{REQUEST_URI} !^/foo/
  RewriteRule ^(.*)$ /foo/$1 [L]
</IfModule>

A disadvantage to this configuration is that--if this .htaccess file is changed, and the snippet is no longer in place or corrupted due to the update, then the site will no longer be accessible as it was. Thus, this type of change should be done when the site is managed or overseen by a competent tech person who understands this type of script. If this is not the case, then it may be better to place all of the site files in the root and have a one-to-one correspondence with the REQUEST_URI and the directory to which it points.

Clone this wiki locally