Apache Rewrite:显示同一目录中两个目录的文件
我需要在浏览器中访问同一目录中两个目录中的文件。
从视觉上看,目录可能如下所示:
/public_html/www.example.com/xml/
/xml/
/public_html/.htaccess
重要说明:此设置支持多个域。
/public_html/www.example1.com/
/public_html/www.example2.com/
http://www.example.com/xml/ 位于 /public_html/www.example.com/ xml/ 如果该文件不存在于该服务器路径然后我需要检查 /xml/ 服务器路径。
显然,我们将从浏览器访问 /public_html/xml/ 路径(例如 www.example.com/xml/),所以假设我们可以看到目录索引使用 Apache 生成所有 XML 文件的链接。我还希望能够从 example.com/xml/ 访问 /xml/ 目录中的文件。
还存在两个目录中都存在具有确切名称的文件的问题。我希望 /public_html/xml/ 目录优先,因此如果用户请求 www.example.com/xml/1.xml 位于 的副本如果可能,将显示 /public_html/xml/1.xml 而不是 /xml/1.xml。
请记住,我想将对两个目录中的所有文件的访问权限合并到一个目录中,我不想为了使其他目录中的文件可访问而使任一目录中的文件不可访问。
这必须使用位于下面的 /.htaccess 的 .htaccess 文件来完成。
I need to access files from two directories in the same directory in a browser.
Visually the directories may look like this:
/public_html/www.example.com/xml/
/xml/
/public_html/.htaccess
Important clarification: this setup supports multiple domains.
/public_html/www.example1.com/
/public_html/www.example2.com/
The XML files requested at http://www.example.com/xml/ are located at /public_html/www.example.com/xml/ and if the file does not exist at that server path then I need to check at the /xml/ server path.
Obviously from the browser we'll be accessing the /public_html/xml/ path (e.g. www.example.com/xml/) so let's say we can see a directory index with Apache generated links to all the XML files. I want to be able to also access the files in the /xml/ directory from example.com/xml/.
There is also the issue of files having the exact name being present in both directories. I'd prefer the /public_html/xml/ directory to take precedence so if a user requests www.example.com/xml/1.xml the copy at /public_html/xml/1.xml is displayed instead of /xml/1.xml if possible.
Remember, I want to MERGE access to all the files in both directories to a single directory, I do not want to make files from either directory inaccessible in order to make the files in other directory accessible.
This must be done using the .htaccess file located at /.htaccess beneath.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
/public_html/xml/ 中类似 .htaccess 的内容
ps: PhysicalPath2AnotherFolder 应该包含但不包含原始目录的 webpath。或者,当然,可以添加额外的 RewriteCond 以便仅从 REQUEST_URI 获取文件名。在那种情况下,它会像(我没有测试它:))..
Something like that .htaccess in /public_html/xml/
ps: PhysicalPath2AnotherFolder should have, but not include, webpath of the original directory in it. Or, of course, it is possible to add additional RewriteCond in order to take only the filename from REQUEST_URI. In that case it would be something like (I did not test it :))..