【问题标题】:Problems with zend and htaccesszend 和 htaccess 的问题
【发布时间】:2012-08-21 08:59:16
【问题描述】:

我正在尝试在共享网络主机上创建 Zend 应用程序,但我无法访问 php.ini 或任何东西。

Zend 已为索引控制器/视图设置并工作。 但是,当我尝试通过“mysite.com/About”访问另一个控制器/视图时,我收到此错误:

Not Found
The requested URL /home/vhosting/g/vhostxx/domains/mysite.com/htdocs/projectname/public/index.php was not found on this server.

我的文件夹结构如下所示:http://framework.zend.com/wiki/display/ZFPROP/Zend+Framework+Default+Project+Structure+-+Wil+Sinclair(见第 9 点)

根目录 (/home/vhosting/g/vhostxx/domains/mysite.com/htdocs/projectname) 中的 .htaccess 如下所示:

php_value include_path "/domains/mysite.com/htdocs/www/library"

Options All -Indexes

php_flag display_errors on

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

而公用文件夹中的 .htaccess 如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

这是公共文件夹中的 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();

以及应用程序文件夹中的(空)引导程序:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

}

我试图访问的控制器是:projectname/application/controllers/AboutController.php 应该可以通过 mysite.com/About 访问,但我收到了前面所述的消息。

我真的不知道我做错了什么或我错过了什么。谁能告诉我如何解决这个问题或如何调试这个问题?

附注:我的主机自动翻译

mysite.com/htdocs/projectname/

进入

mysite.com/htdocs/www/

在 ftp 上,不确定这是问题还是通过 http 访问时发生

【问题讨论】:

  • /about 是否作为目录存在于您的服务器上?它需要,否则您会将其重定向到/index.php,这是怎么回事?
  • @HeatfanJohn 控制器位于 projectname/application/controllers/AboutController.php 和 projectname/application/views/scripts/about/index.phtml 中的视图索​​引控制器的相同设置工作正常

标签: php .htaccess zend-framework shared-hosting


【解决方案1】:

在公共文件夹的 htaccess 文件中,更改:

RewriteRule ^.*$ index.php [NC,L]

包括一个前导斜杠:

RewriteRule ^.*$ /index.php [NC,L]

Apache 猜测重写规则的目标是什么,它是否是文件路径的 URI 路径,看起来它错误地猜测它是文件路径。您也可以在 htaccess 文件中添加一个基础:

RewriteBase /

【讨论】:

  • @JonLin 我很想知道这是如何解决问题的。我对错误消息projectname/public/index.php was not found on this server 感到困惑,我认为它应该存在。此外,修复到位后,重写的请求是否变为projectname/public//index.php,现在带有两个斜杠? TIA,约翰
  • @HeatfanJohn 当向浏览器报告的错误消息是The requested URL /home/vhosting/g/vhostxx/domains/mysite.com/htdocs/projectname/public/index.php was not found on this server.,它将文件系统路径一直暴露到文档根目录,这表明apache正在混淆文件路径和URI路径.在前面添加/(或重写库)告诉apache这是一个URI路径
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 2013-02-20
  • 2011-12-27
相关资源
最近更新 更多