Note that there are some explanatory texts on larger screens.

plurals
  1. POUse a subdirectory as root with htaccess in Apache 1.3
    primarykey
    data
    text
    <p>I'm trying to deploy a site generated with Jekyll and would like to keep the site in its own subfolder on my server to keep everything more organized.</p> <p>Essentially, I'd like to use the contents of <code>/jekyll</code> as the root unless a file similarly named exists in the actual web root. So something like <code>/jekyll/sample-page/</code> would show as <a href="http://www.example.com/sample-page/" rel="noreferrer">http://www.example.com/sample-page/</a>, while something like <code>/other-folder/</code> would display as <a href="http://www.example.com/other-folder" rel="noreferrer">http://www.example.com/other-folder</a>.</p> <p>My test server runs Apache 2.2 and the following <code>.htaccess</code> (adapted from <a href="http://gist.github.com/97822" rel="noreferrer">http://gist.github.com/97822</a>) works flawlessly:</p> <pre><code>RewriteEngine On # Map http://www.example.com to /jekyll. RewriteRule ^$ /jekyll/ [L] # Map http://www.example.com/x to /jekyll/x unless there is a x in the web root. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/jekyll/ RewriteRule ^(.*)$ /jekyll/$1 # Add trailing slash to directories without them so DirectoryIndex works. # This does not expose the internal URL. RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{REQUEST_FILENAME} !/$ RewriteRule ^(.*)$ $1/ # Disable auto-adding slashes to directories without them, since this happens # after mod_rewrite and exposes the rewritten internal URL, e.g. turning # http://www.example.com/about into http://www.example.com/jekyll/about. DirectorySlash off </code></pre> <p>However, my production server runs Apache 1.3, which doesn't allow <code>DirectorySlash</code>. If I disable it, the server gives a 500 error because of internal redirect overload. </p> <p>If I comment out the last section of ReWriteConds and rules:</p> <pre><code>RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{REQUEST_FILENAME} !/$ RewriteRule ^(.*)$ $1/ </code></pre> <p>…everything mostly works: <a href="http://www.example.com/sample-page/" rel="noreferrer">http://www.example.com/sample-page/</a> displays the correct content. However, if I omit the trailing slash, the URL in the address bar exposes the real internal URL structure: <a href="http://www.example.com/jekyll/sample-page/" rel="noreferrer">http://www.example.com/jekyll/sample-page/</a></p> <p>What is the best way to account for directory slashes in Apache 1.3, where useful tools like <code>DirectorySlash</code> don't exist? How can I use the <code>/jekyll/</code> directory as the site root without revealing the actual URL structure?</p> <p><strong>Edit:</strong></p> <p>After a ton of research into Apache 1.3, I've found that this problem is essentially a combination of two different issues listed at the <a href="http://httpd.apache.org/docs/1.3/misc/rewriteguide.html" rel="noreferrer" title="Apache 1.3 URL Rewriting Guide">Apache 1.3 URL Rewriting Guide</a>.</p> <p>I have a (partially) moved DocumentRoot, which in theory would be taken care of with something like this:</p> <pre><code>RewriteRule ^/$ /e/www/ [R] </code></pre> <p>I also have the infamous "Trailing Slash Problem," which is solved by setting the <code>RewriteBase</code> (as was suggested in one of the responses below):</p> <pre><code>RewriteBase /~quux/ RewriteRule ^foo$ foo/ [R] </code></pre> <p>The problem is combining the two. Moving the document root doesn't (can't?) use <code>RewriteBase</code>—fixing trailing slashes requires(?) it… Hmm…</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload