将第三级和第二级域重定向到本地主机上的目录
在 Acrylic DNS 代理的帮助下,以将任何具有顶级域“l”(example.l)的地址重定向到本地主机的方式设置我的本地主机。但我想打开基于二级域的特定文件夹(example.l -> localhost/example) 我认为解决方案可能位于根目录中的 htaccess 文件中(在我的例子中为 C:\wamp\www\)。
我找到了一些子域的代码并对其进行了一些更改,以便它在我的情况下工作:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.l
RewriteCond %{HTTP_HOST} ^([^.]+)\.l
RewriteRule ^$ /$1 [L]
它适用于二级域,但不透明(example.l 变为 example.l/example),并且第三级域被忽略(但我认为可以使用目标目录中的另一个 htaccess 文件进行修复)。 我对正则表达式完全是菜鸟,所以我无法让它正常工作。
有什么想法吗?
顺便说一句,如果我将域添加到 vshost 文件中,它可以正常工作,但是避免为每个域执行此操作是我试图完成的任务的重点......
With the help of Acrylic DNS proxy a set up my localhost in a way that any address with toplevel domain "l" (example.l) is redirected to localhost. But I would like to open specific folder based on second level domain (example.l -> localhost/example)
I think the solution could be in htaccess file which would be located in root directory (C:\wamp\www\ in my case).
I found some code for subdomains and changed it a little so it would work in my case:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.l
RewriteCond %{HTTP_HOST} ^([^.]+)\.l
RewriteRule ^$ /$1 [L]
It works for second level domain but not transparently (example.l becomes example.l/example) and third level domains are ignored (but I think that could be fixed with another htaccess file in target directory).
I'm total noob in regular expressions so I can't get it working properly.
Any ideas?
Btw, if I add domain into the vshost file it works fine, but evading need to do that for every domain is kinda the point of what I trying to accomplish...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要做的是使用 命名虚拟主机,而不是 <代码>mod_rewrite。
这是一个稍微复杂的问题,因为它取决于您的系统配置方式、操作系统以及正在运行的 Apache 版本。
然而,一般来说,它基本上需要在
http.conf
中启用命名虚拟主机,然后添加指向每个主机不同目录的特定配置,如下所示:在生产系统中,例如如果在 Linux 操作系统上运行,您通常会为每个域维护一个单独的
.conf
以使其更容易。编辑:我不是 Windows 用户,所以我不能 100% 掌握正确的目录分隔符格式。我对其进行了更改以匹配我在网上找到的示例。
What you want to do is use Named Virtual Hosts, not
mod_rewrite
.This is a slightly complicated issue, as it depends on the way your system is configured, your OS, and the version of Apache you are running.
In general, however, it basically requires enabling named virtual hosts in your
http.conf
, then adding specific configurations that point to different directories for each host, which looks like this:In a production system, such as one running on a Linux OS, you'd usually maintain a separate
.conf
for each domain to make it easier.Edit: I'm not a Windows user, so I'm not 100% on the correct directory separator format. I changed it to match examples I found online.