1

看看这个示例虚拟主机片段:

<VirtualHost *:80>
    DocumentRoot /web/content
    ServerName   me.example.com
</VirtualHost>

假设/web/content包含 2 个文件,index.htmlpage.html ,以及一个包含yellow.html的子目录colorsindex.html包含和 之类的链接,用于引用 Web 根目录。href="/page.html"href="/colors/yellow.html"/

有没有办法在内部使用me.example.com/test/作为网站的根目录?换句话说,当用户访问http://me.example.com/test/时,我想获取/web/content/index.html。因此,URL 中的/test/本质上是一个虚拟的“文件夹”。

基本上,我希望 me.example.com/test 能够完全按照子域(例如test.me.example.com)的方式运行。设置之类的东西ServerName me.example.com/test(但我知道那不起作用)。

我知道我可以简单地创建一个 REAL 文件夹/web/content/test并将所有内容放在那里,但这会破坏我以 a 开头的链接/,因为它们仍然会将/web/content称为网络根目录。添加类似的指令时会出现同样的问题Alias /test /web/content

我在这里有什么选择吗?也许以某种方式使用 RewriteBase?(我尝试了一些没有运气的事情。)

4

1 回答 1

2

尝试将其放入文档根目录的 htaccess 文件中

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/test/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^ /%1 [L]

这会将/test/URI 路径映射到文档根目录。如果你想说,将其映射到颜色文件夹,你会这样做:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/test/(.*)$
RewriteCond %{DOCUMENT_ROOT}/colors/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/colors/%1 -d
RewriteRule ^ /colors/%1 [L]
于 2012-09-18T18:04:43.023 回答