2

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.

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 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(); 

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

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.

Carlos Robles
  • 10,828
  • 3
  • 41
  • 60
Chirag Shah
  • 1,463
  • 2
  • 18
  • 40
  • You do not need to edit the VirtualHost configuration. Although stated in the documentation for setting up ZF2, it's not a requirement. What problems are you having? – Diemuzi Dec 31 '13 at 16:39
  • Hi Diemuzi thanks for your comments . Each time my site URL contains "public" Ex: www.example.com/public/front , www.example.com/public/page etc. but I want to call all time without pass "public" in URL. – Chirag Shah Jan 01 '14 at 05:10
  • @chirag, you have to map your vhost target directory to `/path/to/zfproject/public`, not `/path/to/zfproject` If you cannot edit vhost file try this: http://stackoverflow.com/questions/12839268/zend-framework-2-without-vhost-configuration?rq=1 – edigu Jan 04 '14 at 16:18

1 Answers1

0

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

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.

In Debian or Ubuntu Linux

To enable Apache mod_rewrite module, type the following commands:

cd /etc/apache2/mods-enabled

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

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

Finally, restart Apache web server to apply your changes.

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

In Fedora, CentOS or Red Hat Linux

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

Restarting Apache Web Server

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 service restart apache2

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

sudo service restart 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]
OlegKrivtsov
  • 752
  • 4
  • 9