AliasMatch除主页之外的所有内容到"内容"夹

时间:2017-06-30 20:35:38

标签: regex apache apache2.4

我将我的所有网站内容(除了主页)放入"内容"站点根目录下的文件夹。这是Apache 2.4.25。

我希望http://www.example.comDirectoryIndex投放index.html(即C:/DocumentRoot/)。以下工作正常。

<Directory "C:/DocumentRoot/website">
    Options None
    AllowOverride None
    Require all granted
</Directory>

然后,我希望http://www.example.com/anything1/anything2DirectoryIndex处为C:/DocumentRoot/content/anything1/anything2提供服务。添加以下内容后,虽然http://www.example.com有效,但访问Forbidden会出现AliasMatch错误。

AliasMatch "^/(.+)$" "C:/DocumentRoot/website/content/$1"
<Directory "C:/DocumentRoot/website/content/">
    Require all granted
</Directory>

知道发生了什么或者有更好/可行的替代方案吗?

2 个答案:

答案 0 :(得分:0)

在这种情况下,mod_rewrite更容易阅读,然后在AliasMatch中扩展为负断言正则表达式。

stack.yaml

答案 1 :(得分:0)

AliasMatch进行更改以便忽略DirectoryIndexindex.html),以使其按预期工作。

AliasMatch "^/(?!index.html)(.+)$" "C:/DocumentRoot/website/content/$1"

(?!index.html)可确保隐式index.html不匹配。 (.+)选择其他内容并从content文件夹中提取。

相关问题