mod_rewrite docroot 到多个子文件夹,具体取决于子文件夹名称

发布于 2024-09-11 11:31:06 字数 804 浏览 2 评论 0原文

我一直在尝试让一些 RewriteRules 正常工作,并且在仅用于一台主机而不是多台主机时取得了成功。

我希望“http://preview.domain.com”指向“http://preview.domain.com/dir1" 或 "http://preview.domain.com/dir2" 等。 Dir1 和 Dir2 是因为它们包含指向真实域的 ProxyPass。这是我目前所拥有的:

RewriteCond %{REQUEST_URI} !/dir1
RewriteRule ^(.*)$ /dir$1 [R]

<Location /dir1>
ProxyPass http://dir1.com
</Location>

我无法让 dir2 规则与上述规则一起工作。如果可能的话,我希望使这个动态化,因为它们有大约 70 个文件夹,并且还在不断增长。 “http://preview.domain.com”本质上是一个指向我的开发服务器以显示开发的域内容而不是产品内容,而无需修改网站代码。有人可以提供帮助吗?

I've been trying to get some RewriteRules working and am successful when just using for one host, but not multiple.

I'm wanting "http://preview.domain.com" to point to "http://preview.domain.com/dir1" or "http://preview.domain.com/dir2", etc. Dir1 and Dir2 are as they contain a ProxyPass that points to the real domain. Here is what I have currently :

RewriteCond %{REQUEST_URI} !/dir1
RewriteRule ^(.*)$ /dir$1 [R]

<Location /dir1>
ProxyPass http://dir1.com
</Location>

I can't get the dir2 Rules to work beside the ones above. I am wanting to make this dynamic if possible as their are about 70 folders and growing. "http://preview.domain.com" is essentially a domain to point to my dev server to show dev content instead of prod content without having to modify the website code. Could anyone provide help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-09-18 11:31:06

我不太明白你想做什么。如果您希望 http://preview.domain.com/nameofsite/path 映射到 http://nameofsite.com/path (其中 nameofsite 是您使用的任何域名的占位符),您可以使用

RewriteRule ^/([^/]+)(/.*)$ http://$1.com$2 [P]

,然后就不需要 Location 块。

I don't exactly understand what you're trying to do. If you want http://preview.domain.com/nameofsite/path to map to http://nameofsite.com/path (where nameofsite is a placeholder for whatever domain name you're using), you could use

RewriteRule ^/([^/]+)(/.*)$ http://$1.com$2 [P]

and then you wouldn't have any need for the Location block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文