更改 Zend_Framework 项目中的公共文件夹位置?
我希望我的服务器上的 public_html 文件夹成为我的 zend 项目中的公共文件夹。 你们知道我该怎么做吗?现在我必须使用domain.com/public 查看我的网站
我尝试将index.php 文件更改为此(更改了目录)
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . 'application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . 'library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
但这不起作用。知道如何解决这个问题吗?
基本上我想要一个像这样的目录结构:
public_html/
----application/
----library/
----index.php
或者还有其他方法可以实现此目的吗?无论如何,我希望“public”从我的网址中消失。
有什么想法吗?
I want my public_html folder on my server to be the public folder in my zend project.
You guys any idea how I can do this? Right now I have to view my site with domain.com/public
I tried changing the index.php file to this (changed the directories)
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . 'application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . 'library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
But this doesn't work. Any idea how I can get this fixed?
Basically I want a directory structure like this:
public_html/
----application/
----library/
----index.php
Or is there some other way to achieve this? I want 'public' gone from my URL anyway.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的 .htaccess 设置正确,您不必担心人们访问您的库文件夹,简单的重写规则可以防止这种情况。
下面是我用来删除index.php上的公共目录的方法
,这是我的.htaccess
if your .htaccess is set up right you dont have to worry about people getting to your library folder, simple rewrite rules can prevent that.
Below is what ive used to get rid of the public directory on my index.php
and this is my .htaccess
这是错误的做法!我们之所以有一个公用文件夹,并且几乎所有其他东西都在同一级别,是出于安全原因!我们不想将我们的库和应用程序代码放在公共文件夹中!
您唯一需要更改的是服务器(apache)虚拟主机配置,以便它指向您的公共文件夹作为文档根目录。
That's the wrong approach! The reason why we have a public folder and almost everything else is on the same level is a reason of security! We don't want to have our libraries and application code in our public folder!
The only thing you need to change is your server (apache) vhost configuration so that it points to your public folder as the document root.
这篇文章提出了一种非常简单的方法(本质上,删除
public
并将所有 ZF 文件推送到子文件夹中),但它还引用了其他几种方法。特别是,该帖子的评论建议您只需修改子域根目录下的
.htaccess
文件,即可将所有请求推送到公共文件夹中:然后在
public 文件夹,您保留标准的
.htaccess
。在最坏的情况下,您还必须在Bootstrap
期间设置应用程序的baseUrl
,可能是通过 config。This post suggests one pretty easy approach (essentially, remove
public
and push all the ZF files into a sub-folder), but it also references several other approaches.In particular, the comments on that post suggest that you can simply modify the
.htaccess
file at the root of your subdomain to push all requests down into the public folder:Then in the
public
folder, you keep the standard.htaccess
. In the worst case, you also have to set thebaseUrl
of the app duringBootstrap
, probably via config.