将子域重定向到子目录
我已经阅读了这里和谷歌上有关重定向的所有主题,但我是一名程序员,我无法继续下去。
我安装了 Apache 2.2。 Web 根目录是 C:\Apache\htdocs。我的网络管理员为我设置了一个指向 Apache 服务器的本地域。域是 myPhpApp.ourcompany.local。这个子域有效,它显示了 Apache“它有效”页面。
现在我在 C:\Apache\htdocs\myPhpApp 中有一个网站,我希望 Apache 将 myPhpApp.ourcompany.local 重定向到此目录。浏览网站时,URL 应始终保留为 myPhpApp.ourcompany.local,例如:myPhpApp.ourcompany.local/index.php、myPhpApp.ourcompany.local/data.php 等。
我不知道如何实现这一目标?模组重写、虚拟主机、两者的结合? 我已经得到了这个,但这不起作用:
<VirtualHost myphpapp.ourcompany.local>
DocumentRoot /myphpapp/
ServerName www.example1.com
RewriteEngine on
RewriteRule ^/$ /myphpapp/ [R]
</VirtualHost>
实际上我得到:
禁止
您无权访问 /myphpapp/ 在此服务器上。 有人可以帮忙吗?
编辑 也许我忘了提及:我没有将其放入 www 根目录(C:/Apache/htdocs)中,因为我在那里有更多应用程序。 我在 thdocs 中有 3 个目录:myphpapp、myoldapp、mytestapp。作为目标,我希望有 3 个子域指向每个目录。
i've already read all topics here and on google about redirection but i'm a programmer and i cant get it going.
I have Apache 2.2 installed. The web root is C:\Apache\htdocs. My network admin set me up a local domain that points to the server with Apache. The domain is myPhpApp.ourcompany.local. And this subdomain works, it shows the Apache "It works" page.
Now i have a website in C:\Apache\htdocs\myPhpApp and i want Apache to redirect the myPhpApp.ourcompany.local to this directory. The URLs should stay while browsing the website always as myPhpApp.ourcompany.local for example: myPhpApp.ourcompany.local/index.php, myPhpApp.ourcompany.local/data.php and so on.
I dont know how to achieve this? Mod-rewrite, virtual hosts, combination of both?
i have got this and this does not work:
<VirtualHost myphpapp.ourcompany.local>
DocumentRoot /myphpapp/
ServerName www.example1.com
RewriteEngine on
RewriteRule ^/$ /myphpapp/ [R]
</VirtualHost>
In effect i get:
Forbidden
You don't have permission to access
/myphpapp/ on this server.
Can anyone help?
EDIT
Maybe i forgot to mention: i dont put this into the www root which is C:/Apache/htdocs becuase i have more apps in there.
i have 3 directories in thdocs: myphpapp, myoldapp, mytestapp. As a target i want to have 3 subdomains that point to each directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这将是尼古拉和克罗莫坦的答案的结合:
I think it will be a combination of Nikola's and cromestant's answers:
首先,您不需要像这样简单的事情的重写规则。
我假设您需要遵循 VirtualHost 定义
“VirtualHost *”部分告诉 Apache 在哪个接口和可选端口上侦听。
ServerName 告诉我们将使用哪个域名来标识该虚拟主机。
First of all, you don't need a rewrite rule for simple thing as this.
I assume you need following VirtualHost definition
"VirtualHost *" part tells Apache on which interface and optionally port to listen to.
ServerName tells which domain name will be used to identify this virtual host.
apache 配置中的文档根目录应该指向您拥有该应用程序的目录,正如您在问题中所述的那样,仅此
而已。
重新启动或重新加载您的 apache,然后进行测试。
Document root in your apache config should point to your directory where you have the app, in what you stated in your question it should be
and that is all.
restart or reload your apache, and test.