在Apache 1.3中使用htaccess作为root用户的子目录

我正在尝试部署一个由Jekyll生成的站点,并希望将站点保存在我的服务器上的子文件夹中,以保持一切更有条理。

本质上,我想使用/jekyll的内容作为根目录,除非在实际的web根目录中存在一个类似命名的文件。 所以/jekyll/sample-page/会显示为http://www.example.com/sample-page/ ,而/other-folder/会显示为http://www.example.com/other – 文件夹 。

我的testing服务器运行Apache 2.2,下面的.htaccess (改编自http://gist.github.com/97822 )完美地工作:

 RewriteEngine On # Map http://www.example.com to /jekyll. RewriteRule ^$ /jekyll/ [L] # Map http://www.example.com/x to /jekyll/x unless there is ax 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, eg turning # http://www.example.com/about into http://www.example.com/jekyll/about. DirectorySlash off 

但是,我的生产服务器运行Apache 1.3,不允许DirectorySlash 。 如果我禁用它,由于内部redirect超载,服务器会提供500错误。

如果我注释掉ReWriteConds和规则的最后一部分:

 RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{REQUEST_FILENAME} !/$ RewriteRule ^(.*)$ $1/ 

…所有内容都可以正常工作: http : //www.example.com/sample-page/显示正确的内容。 但是,如果我省略了斜线,则地址栏中的URL将显示真实的内部URL结构: http : //www.example.com/jekyll/sample-page/

在Apache 1.3中解决目录斜杠的最好方法是什么? DirectorySlash等有用的工具不存在? 我怎样才能使用/jekyll/目录作为网站的根,而不透露实际的url结构?

编辑:

经过对Apache 1.3的大量研究,我发现这个问题基本上是Apache 1.3 URL重写指南中列出的两个不同问题的组合。

我有一个(部分)移动的DocumentRoot,理论上这将被照顾与这样的事情:

 RewriteRule ^/$ /e/www/ [R] 

我也有臭名昭着的“拖尾问题”,这是通过设置RewriteBase解决的(如下面其中一个回答中所build议的那样):

 RewriteBase /~quux/ RewriteRule ^foo$ foo/ [R] 

问题在于两者结合。 移动文档根不能(不能?)使用RewriteBase修剪尾随斜线需要(?)它…嗯…

终于明白了,经过一个星期的尝试。 RewriteRules真的是巫术…

 RewriteEngine On # Map http://www.example.com to /jekyll. RewriteRule ^$ /jekyll/ [L] # Map http://www.example.com/x to /jekyll/x unless there is ax in the web root. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/jekyll/ RewriteRule ^(.*)$ /jekyll/$1 # Add trailing slash to directories within jekyll # This does not expose the internal URL. RewriteCond %{SCRIPT_FILENAME} -d RewriteRule ^jekyll/(.*[^/])$ http://www.example.com/$1/ [R=301] 

不需要DirectorySlash 。 它神奇地所有的作品。

你可以简单地使用:

 RewriteBase /jekyll 

一切都从这一点开始。