别名将除主页以外的所有内容匹配到 "content" 文件夹
AliasMatch everything except home page to "content" folder
我将网站的所有内容(主页除外)放入网站根目录下的 "content" 文件夹中。这是 Apache 2.4.25。
我希望 http://www.example.com
在 C:/DocumentRoot/
为 DirectoryIndex
(即 index.html
)服务。以下内容适用于此。
<Directory "C:/DocumentRoot/website">
Options None
AllowOverride None
Require all granted
</Directory>
然后我想让 http://www.example.com/anything1/anything2
在 C:/DocumentRoot/content/anything1/anything2
为 DirectoryIndex
服务。添加以下内容后,访问 http://www.example.com
会出现 Forbidden
错误,尽管 AliasMatch
有效。
AliasMatch "^/(.+)$" "C:/DocumentRoot/website/content/"
<Directory "C:/DocumentRoot/website/content/">
Require all granted
</Directory>
知道发生了什么或有 better/working 替代方案吗?
在这种情况下,mod_rewrite 更易于阅读,稍后在 AliasMatch 中扩展否定断言正则表达式。
RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/content
RewriteRule ^/(.+) "C:/DocumentRoot/website/content/"
对 AliasMatch
的更改使其忽略 DirectoryIndex
(index.html
) 使其能够按预期工作。
AliasMatch "^/(?!index.html)(.+)$" "C:/DocumentRoot/website/content/"
(?!index.html)
确保隐式 index.html
不匹配。 (.+)
选择其他任何东西并将其从 content
文件夹中拉出。
我将网站的所有内容(主页除外)放入网站根目录下的 "content" 文件夹中。这是 Apache 2.4.25。
我希望 http://www.example.com
在 C:/DocumentRoot/
为 DirectoryIndex
(即 index.html
)服务。以下内容适用于此。
<Directory "C:/DocumentRoot/website">
Options None
AllowOverride None
Require all granted
</Directory>
然后我想让 http://www.example.com/anything1/anything2
在 C:/DocumentRoot/content/anything1/anything2
为 DirectoryIndex
服务。添加以下内容后,访问 http://www.example.com
会出现 Forbidden
错误,尽管 AliasMatch
有效。
AliasMatch "^/(.+)$" "C:/DocumentRoot/website/content/"
<Directory "C:/DocumentRoot/website/content/">
Require all granted
</Directory>
知道发生了什么或有 better/working 替代方案吗?
在这种情况下,mod_rewrite 更易于阅读,稍后在 AliasMatch 中扩展否定断言正则表达式。
RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/content
RewriteRule ^/(.+) "C:/DocumentRoot/website/content/"
对 AliasMatch
的更改使其忽略 DirectoryIndex
(index.html
) 使其能够按预期工作。
AliasMatch "^/(?!index.html)(.+)$" "C:/DocumentRoot/website/content/"
(?!index.html)
确保隐式 index.html
不匹配。 (.+)
选择其他任何东西并将其从 content
文件夹中拉出。