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

And*_*rew 28 apache .htaccess subdirectory jekyll

我正在尝试部署使用Jekyll生成的网站,并希望将该网站保留在我自己的服务器上的子文件夹中,以使所有内容更有条理.

本质上,我想使用/jekyll作为根的内容,除非在实际的Web根目录中存在类似名称的文件.因此,像/jekyll/sample-page/会显示为http://www.example.com/sample-page/,而像/other-folder/将显示为http://www.example.com/other-folder.

我的测试服务器运行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 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
Run Code Online (Sandbox Code Playgroud)

但是,我的生产服务器运行Apache 1.3,但不允许DirectorySlash.如果我禁用它,服务器会因内部重定向过载而产生500错误.

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

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !/$
RewriteRule ^(.*)$ $1/
Run Code Online (Sandbox Code Playgroud)

...一切都很有效: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]
Run Code Online (Sandbox Code Playgroud)

我也有臭名昭着的"尾随斜线问题",这可以通过设置RewriteBase(如下面的一个答案中的建议)来解决:

RewriteBase    /~quux/
RewriteRule    ^foo$  foo/  [R]
Run Code Online (Sandbox Code Playgroud)

问题是将两者结合起来.移动文档根不(不能?)使用RewriteBase-fixing尾部斜杠需要(?)它...嗯......

And*_*rew 59

经过一周的尝试,终于得到了它.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 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 within jekyll
# This does not expose the internal URL.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^jekyll/(.*[^/])$ http://www.example.com/$1/ [R=301]
Run Code Online (Sandbox Code Playgroud)

没必要DirectorySlash.神奇地一切都有效.


Mar*_*ona 12

你可以简单地使用:

RewriteBase   /jekyll
Run Code Online (Sandbox Code Playgroud)

一切都从那一点开始.


Uma*_*mid 5

对我有用的唯一简单的解决方案就在这里

\n
RewriteEngine on\nRewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]\nRewriteCond %{HTTP_HOST} ^www.domain-name.com$\nRewriteCond %{REQUEST_URI} !folder/\nRewriteRule (.*) /folder/$1 [L]\n
Run Code Online (Sandbox Code Playgroud)\n

将此代码放入您的 .htaccess 文件中。

\n
\n

domain-name.com \xe2\x80\x93 输入您自己的域名

\n
\n
\n

文件夹 \xe2\x80\x93 键入包含测试/开发网站的子文件夹的名称

\n
\n