如何在不访问域配置的情况下通过符号链接在域根目录外使用 path/directory?
Howto use path/directory outside the domain root via symlink without access to domain config?
我正在使用一个不允许编辑或访问 Apache 配置文件的共享托管平台。
目标是从指向不同域根的两个不同域访问相同文件:
test.example.com ---> /test_root/web
public.example.com ---> /public_root/web
现在我想使用 test.example.com/some/files/...
和 public.example.com/some/files/...
访问 相同的 文件
当然我可以简单地将文件复制到 /test_root/web/some/files/...
和 /public_root/web/some/files/...
但这显然只是一个例子。实际上,这些文件是一个帮助台系统,应该将其集成到测试站点和 public 站点中。复制文件将包括维护两个不同的系统等。
目标是将文件放置在两个域根之外的某个位置,并使它们在两个域中都可用:
/test_root/web/some/files ---> /path/to/some/files
/public_root/web/some/files ---> /path/to/some/files
我创建了符号链接来实现此目的 (ln -s ...
),但这行不通。当我访问其中一个域(例如 test.example.com/some/files)时,我只得到一个空白页面,没有任何错误信息。
我假设 Apache 未配置为遵循符号链接。如果无法访问 Apache 配置,我既无法检查也无法修复它。
向 .../web/.htacess
添加符号链接没有任何区别:
// test_root/web/.htaccess
Options +FollowSymLinks
所以问题是: 我怎样才能使域根之外的文件在域内可用?这可能吗?这可能使用符号链接吗?
将此添加到您的 .htaccess
文件中。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} test.example.com/path/to/files [NC]
RewriteRule ^(.*)$ http://public.example.com/path/to/files [R=301,NC]
测试这段代码。 /path/to/files
必须在 /public_root/web/
之下。
类似于 /public_root/web/path/to/files/
我正在使用一个不允许编辑或访问 Apache 配置文件的共享托管平台。
目标是从指向不同域根的两个不同域访问相同文件:
test.example.com ---> /test_root/web
public.example.com ---> /public_root/web
现在我想使用 test.example.com/some/files/...
和 public.example.com/some/files/...
当然我可以简单地将文件复制到 /test_root/web/some/files/...
和 /public_root/web/some/files/...
但这显然只是一个例子。实际上,这些文件是一个帮助台系统,应该将其集成到测试站点和 public 站点中。复制文件将包括维护两个不同的系统等。
目标是将文件放置在两个域根之外的某个位置,并使它们在两个域中都可用:
/test_root/web/some/files ---> /path/to/some/files
/public_root/web/some/files ---> /path/to/some/files
我创建了符号链接来实现此目的 (ln -s ...
),但这行不通。当我访问其中一个域(例如 test.example.com/some/files)时,我只得到一个空白页面,没有任何错误信息。
我假设 Apache 未配置为遵循符号链接。如果无法访问 Apache 配置,我既无法检查也无法修复它。
向 .../web/.htacess
添加符号链接没有任何区别:
// test_root/web/.htaccess
Options +FollowSymLinks
所以问题是: 我怎样才能使域根之外的文件在域内可用?这可能吗?这可能使用符号链接吗?
将此添加到您的 .htaccess
文件中。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} test.example.com/path/to/files [NC]
RewriteRule ^(.*)$ http://public.example.com/path/to/files [R=301,NC]
测试这段代码。 /path/to/files
必须在 /public_root/web/
之下。
类似于 /public_root/web/path/to/files/