PHP 项目需要放置在 www 根目录中 - 如何使用 .htaccess 修复?
我必须使用其他人的几个 PHP 项目,这些项目的路径是硬编码的,这样我就必须一次将每个项目放入我的 /var/www/
目录中才能运行它- 而不是能够在其自己的子目录中访问它,例如 /var/www/project_name
。
有没有办法解决这个问题,这样我就不必将每个项目直接放在我的 webroot 目录中?必须这样做才能让我在本地 LAMP 服务器上一次只能处理一个项目!
编辑:如果以“VirtualHost”方式进行操作,project_name
的ServerName
是什么?我只尝试过 project_name
但这似乎不起作用。
I have to work with several of someone else's PHP projects that have paths hard-coded in such a way that I have to put each project in my /var/www/
directory one at a time to run it - instead of being able to it in its own subdirectory, like /var/www/project_name
.
Is there some way to work around this so I don't have to put each project directly in my webroot directory? Having to do that lets me only work with one project at a time with my local LAMP server!
Edit: For doing it the "VirtualHost" way, what would my ServerName
be for project_name
? I've tried just project_name
but that doesn't seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将这样的内容
hosts
文件在 apache 中为每个主机创建一个虚拟服务器,每个服务器都有自己的 webroot
(还有更重要的)日志文件。
通过 http://localproject1、http://localproject2, ...
something like this to your
hosts
fileIn apache create a virtual server for each of them, each with their own webroot
(and what could be more important) logfiles.
browse to them via http://localproject1, http://localproject2, ...
基本上你有很多选择,如果你想为每个项目使用不同的 URL,你需要编辑你的主机文件,启用 NameVirtualHost 并使用 VirtualHost。
另一种方法是将每个项目放在 /var/www/project_name 中,并在每个文件夹的 .htaccess 中设置重写基础,如下所示,这样您就可以使用绝对 URL,并且项目不会中断
Basically you have many options, if you want to use different URL's per project you need to edit your hosts file, enable NameVirtualHost and use VirtualHost.
The other way is by placing each project in /var/www/project_name and set the rewrite base in your .htaccess on each folder as follows, so you can use absolute URLs and the project won't break