gpt4 book ai didi

php - 更改 Zend_Framework 项目中的公用文件夹位置?

转载 作者:可可西里 更新时间:2023-11-01 13:23:27 26 4
gpt4 key购买 nike

我希望我服务器上的 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

或者有其他方法可以实现吗?无论如何,我希望“公开”从我的 URL 中消失。

有什么想法吗?

最佳答案

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

下面是我用来删除 index.php 上的公共(public)目录的内容

$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>

关于php - 更改 Zend_Framework 项目中的公用文件夹位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5756462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com