外部目录和所有子目录的 Apache 别名

Apache Alias For External Directory And All Sub Directories

我想为我的网站添加别名。因此该网站。com/alias 将转到根文件夹之外的文件夹。此文件夹包含一个不同的网站,因此我希望能够将此别名视为一个子域。

AliasMatch  ^/subdir1/(.*)$ /var/www/otherfolder/subdir1/

我希望这会匹配所有调用,这样 website.com/subdir1/css/style.css 也将是一个有效路径,但所有这些都返回 404 错误。

如何使别名与通配符匹配,以便条目覆盖别名文件夹中的所有子目录。我希望能够在 apache 级别执行此操作,而不是必须在 .htaccess 文件中执行此操作,因为那里的事情已经非常复杂,所以我想尽可能绕过它。

如果加载了 mod_alias.so http 模块,别名将起作用。您需要编辑 httpd.conf 配置文件并添加以下行并重新启动 httpd。

LoadModule alias_module modules/mod_alias.so

这个问题是由基地 URL 引起的。 “/”作为基础 url 无法正常工作。相反,我能够根据此处的答案解决它。

Set RewriteBase to the current folder path dynamically

RewriteCond %{REQUEST_URI}:: ^(.*?/)(.*)::$
RewriteRule ^(.*)$ - [E=BASE:%1]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]

以上内容足以解决基于我链接的post的问题。