使zend Framework 2在没有虚拟主机的情况下工作 [英] Make zend framework 2 work without Virtual Host

查看:102
本文介绍了使zend Framework 2在没有虚拟主机的情况下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Zend Framework 2完成了我的第一个Web应用程序,并且准备将其在线。但可能是网络托管服务商不允许我更改我的虚拟主机配置!允许使用.htaccess文件。

I had finished my first web application using Zend Framework 2 and I'm about to put it online. But may web host doesn't allow me to change my vhost configuration! The .htaccess file is allowed.

我在公用文件夹中的.htaccess文件如下:

My .htaccess file in Public folder is like this:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

我的文件夹目录结构是这样的:

My Folder Directory Structure is like this:

 -ProjectName  
  -config
  -module
  -vendor
    - zendframework
  -public
    - css
    - img
    - JS
    - index.php 

Index.php文件:

Index.php File:

<?php
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
    return false;
}

// Setup autoloading
require 'init_autoloader.php';

// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run(); 

所以我的问题是:如何仅使用.htaccess文件设置我的ZF2应用程序?

So my question is: How to set up my ZF2 app with only .htaccess files?

我也想在我的网站www.example.com运行时调用默认的 Front模块调用。

Also I want to call default my "Front" Module Call While my site www.example.com run.

您的答案将不胜感激。
预先感谢。

Your Answer will be appreciated. Thanks in advance.

推荐答案

似乎您需要启用mod_rewrite模块并重新启动Apache。

It seems that you need to enable the mod_rewrite module and restart Apache.

Zend Framework 2要求您启用Apache的* mod_rewrite *模块。
* mod_rewrite *模块用于根据某些规则重写请求的URL,
将站点用户重定向到另一个URL。

Zend Framework 2 requires that you have Apache's *mod_rewrite* module enabled. The *mod_rewrite* module is used to rewrite requested URLs based on some rules, redirecting site users to another URL.

在Debian或Ubuntu Linux

要启用Apache mod_rewrite 模块,请键入以下命令:

To enable Apache mod_rewrite module, type the following commands:

cd / etc / apache2 / mods-enabled

sudo ln -s ../mods-available/rewrite.load ./rewrite.load

以上命令创建 mods-enabled 目录中的符号链接,
这样可以在现代版本的Apache Web服务器中启用模块。

The command above creates a symbolic link in the mods-enabled directory, this way you enable modules in modern versions of Apache web server.

最后,重新启动Apache Web服务器以应用您的更改。

Finally, restart Apache web server to apply your changes.

I> Linux中的符号链接是Windows中的快捷方式类似物。

I> A symbolic link in Linux is an analog of a shortcut in Windows.

在Fedora,CentOS或Red Hat Linux中

在这些Linux发行版中, mod_rewrite 默认情况下处于启用状态,因此您无需执行
任何事情。

In these Linux distributions, mod_rewrite is enabled by default, so you don't need to do anything.

编辑配置文件后,通常必须重新启动Apache HTTP Server
才能应用更改。您可以使用以下命令(在Debian或Linux Ubuntu中)执行此操作:

After editing configuration files, you usually have to restart Apache HTTP Server to apply your changes. You do this with the following command (in Debian or Linux Ubuntu):

sudo服务重启apache2

或以下版本(在Fedora,CentOS或Red Hat中):

or the following (in Fedora, CentOS or Red Hat):

sudo服务重新启动httpd

因此,您应该看到如下输出:

As a result, you should see output like below:

* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified 
domain name, using 127.0.0.1 for ServerName
  ... waiting apache2: Could not reliably determine the server's fully 
qualified domain name, using 127.0.0.1 for ServerName                   [OK]

这篇关于使zend Framework 2在没有虚拟主机的情况下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆