我是 Zend 框架的新手。我想知道如何在共享主机上实现 zend 框架。由于具有Zend Framework文件夹结构,所有视图文件都放入“公共”文件夹中。

认为

“/”是我的主要根文件夹,公众就像“/public”

这样网址就变成了“http://站点/公共/. 。...布拉布拉……”

它是否正确?

或者还有其他方法吗?

我没有任何创建虚拟主机的权限。

那么该怎么办?

我希望你能理解我的问题。如果没有,请问我。

谢谢你!

有帮助吗?

解决方案

我认为最好的方法是删除从(Zend Framework的目录结构)公共目录中的.htaccess,并把它与下面的内容到你的“根”目录:

 
RewriteEngine On

RewriteRule ^.htaccess$ - [F] RewriteCond %{REQUEST_URI} ="" RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.$ RewriteRule ^(.)$ /public/$1 RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^.*$ - [NC,L]

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

其他提示

,则包括此.htacces您的基本路径下的文件(也就是公/../):

RewriteEngine On

# Exclude some directories from URI rewriting
#RewriteRule ^(dir1|dir2|dir3) - [L]

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

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

和离开那是publc目录丢失地下htaccess的。

所以,你将有2个.htaccess文件,一个公共目录下(从Zend框架文档中的普通一员)和第二个你的基本路径(一个我张贴以上)下。

您应该把你的项目的公用文件夹在主机WWW文件夹,让您的地址将成为yourdomain.com/。 你的源代码文件夹,如图书馆,应用程序......应在与WWW文件夹同一级别的地方,在它没有。此方法将推广你的网站的安全性

事实上,这不是运行一个共享的主机Zend框架应用的最佳idead。我真的建议得到一个虚拟专用主机(VPS)。有很好的和廉价hostings在那里与Zend框架和已经安装,并定期更新其他框架。我在 servergrove 和它一直很大,到目前为止!

但是,这并不意味着你不能让一个共享的主机工作。你只需要相当具有.htacess工作。把公共文件夹的内容到你的根目录,并在bootstrap.php中调整自己的路径,确保所有其他文件夹不能直接访问并使用通过您的index.php路由一切通常的做法ZF。

从ArneRie答案并没有为我工作,我终于结束了使用洛伦佐Albertons解决方案 。希望这是帮助别人得到更快的解决方案。

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

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

其实我已经搜索了一下,发现很多答案(其中大部分在这里SO),但他们没有为我工作。所以最后找到了解决方案 - 在根目录的.htaccess:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php

此一个从 http://framework.zend.com /维基/显示/ ZFDEV /配置+你+ URL +重写 和根目录的index.php:

<?php 
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';
?>

此一个从 http://akrabat.com/ Zend的框架/ Zend的框架上,一个共享 - 主机/ 和它的作品对我来说,即使有在根文件夹等项目目录 - 像论坛左右。 认为它可能是有用的人:)

此外罗布艾伦写一个好的解决方案

我使用的 Zend框架2 ,它为我工作。 Alghough我没有做过部分的 “引用面向公众的文件”从上面的链接。

我刚改变的代码在我的 layout.phtml 自:

$basePath = $this->basePath();

为:

$basePath = $this->basePath();
if (defined('RUNNING_FROM_ROOT')) {
    $basePath .= 'public/';
}

我已经在同样的情况,并已提出了Zend库文件夹下下的公共像“SRC” - 并使用一个.htaccess从全部拒绝。你必须要兼顾一对夫妇的路径,但它工作正常。

。 。 。如何Magento的使用Zend框架???我使用的XAMPP,我没有在本地安装的Magento没有修改php.ini文件,在http.conf也没有虚拟主机。

我最近遇到了这个问题,通过这个线程我找到了解决方案。我用的是zf2所以我所要做的就是将 zend 相关文件放在我们可以命名的目录中 src. 。该目录将驻留在公共目录或根目录中(例如 /www)

  1. 在“src”目录中创建一个 .htaccess 文件并添加 Deny from All 指令。

  2. 在索引文件中,将工作目录更改为 src 文件夹,执行以下操作:

    define('SRC_ROOT', 'src');
    chdir(SRC_ROOT);
    

...你就可以走了!

设置虚拟主机内的httpd.conf或额外/ httpd的-vhosts.conf通常完成。如果您正在使用的httpd-vhosts.conf,确保此文件是由您的主要httpd.conf文件包括在内。一些Linux发行版(比如:Ubuntu的)包的Apache,这样的配置文件存储在/ etc / apache2的,并创建每个虚拟主机一个文件夹的/ etc / apache2的/启用的网站,里面。在这种情况下,你会放置虚拟主机块以下,进入文件/ etc / apache2的/启用的站点 - / ZF2教程。

确保了NameVirtualHost被定义并设定为“*:80”或类似的,然后沿着这些线限定一个虚拟主机:

Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.

Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:

 <VirtualHost *:80>
     ServerName zf2-tutorial.localhost
     DocumentRoot /path/to/zf2-tutorial/public
     SetEnv APPLICATION_ENV "development"
     <Directory /path/to/zf2-tutorial/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1.

请确保您更新你的/ etc / hosts或C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ ETC \ hosts文件,ZF2-tutorial.localhost被映射到127.0.0.1

我建议simpliest:开发的方式您的应用程序,其中的index.php是在你的根(甚至更好 - 始终定义PUBLIC_PATH - 在你的index.php dirname(__FILE__);,并相对于这个恒定的链接)。随着应用程序和库文件夹。您可以轻松地让他们从在.htaccess使用deny from all外面不可访问。

在PUBLIC_PATH常数也有助于当你公开不公开。 (公共HTML或/公共HTML / WWW(在我的情况))

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top