更改 Zend_Framework 项目中的公共文件夹位置?

发布于 2024-11-02 21:26:08 字数 1107 浏览 0 评论 0原文

我希望我的服务器上的 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 技术交流群。

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

发布评论

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

评论(3

睡美人的小仙女 2024-11-09 21:26:08

如果您的 .htaccess 设置正确,您不必担心人们访问您的库文件夹,简单的重写规则可以防止这种情况。

下面是我用来删除index.php上的公共目录的方法

$path = realpath(dirname(__FILE__));
$dirs = array(
        $path . '/library',
        get_include_path()
);
$includes = implode(PATH_SEPARATOR, $dirs);
set_include_path($includes);

defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

require_once 'Zend/Application.php';

$application = new Zend_Application(
                APPLICATION_ENV,
                APPLICATION_PATH . '/configs/application.ini'
);

,这是我的.htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule \.svn/.* index.php [L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>

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

$path = realpath(dirname(__FILE__));
$dirs = array(
        $path . '/library',
        get_include_path()
);
$includes = implode(PATH_SEPARATOR, $dirs);
set_include_path($includes);

defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

require_once 'Zend/Application.php';

$application = new Zend_Application(
                APPLICATION_ENV,
                APPLICATION_PATH . '/configs/application.ini'
);

and this is my .htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule \.svn/.* index.php [L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
謌踐踏愛綪 2024-11-09 21:26:08

这是错误的做法!我们之所以有一个公用文件夹,并且几乎所有其他东西都在同一级别,是出于安全原因!我们不想将我们的库和应用程序代码放在公共文件夹中!

您唯一需要更改的是服务器(apache)虚拟主机配置,以便它指向您的公共文件夹作为文档根目录。

<VirtualHost *:80>
DocumentRoot /path/to/your/public/folder
ServerName domain.com
    <Directory path/to/your/public/folder>
        AllowOverride All
    </Directory>
</VirtualHost>

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.

<VirtualHost *:80>
DocumentRoot /path/to/your/public/folder
ServerName domain.com
    <Directory path/to/your/public/folder>
        AllowOverride All
    </Directory>
</VirtualHost>
魂牵梦绕锁你心扉 2024-11-09 21:26:08

这篇文章提出了一种非常简单的方法(本质上,删除 public 并将所有 ZF 文件推送到子文件夹中),但它还引用了其他几种方法。

特别是,该帖子的评论建议您只需修改子域根目录下的 .htaccess 文件,即可将所有请求推送到公共文件夹中:

RewriteEngine on
RewriteRule ^.* /public/$0 [L]

然后在 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:

RewriteEngine on
RewriteRule ^.* /public/$0 [L]

Then in the public folder, you keep the standard .htaccess. In the worst case, you also have to set the baseUrl of the app during Bootstrap, probably via config.

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