1

I have been using Zend Framework for a while now. I am having an issue since de beginning an after reading a lot of documentation i was wondering why all exemples dont mention it.

If I am right, the MVC design pattern favorise a single entry point to interract with the application. With Zend its the index.php file in the public folder.

I tried to use this way with the default (v 1.09) .htaccess that Zend provides :

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

and the default index.php file :

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

But so far I have been unable to use the single entry point, I had to duplicate the index file and give it the name of the related controller. This way instead of getting a 500 server error, I was able to get the page to load normally.

So, my question is : What am I getting wrong to get my application to work? Is it the normal way of doing things?

Thanks

EDIT @ 13h55

I have reconfigured my server to access the zend installation through a virtual host instead of an alias and it seems that that was the error.

I went from an alias looking like :

Alias /elul/ "c:\wamp\www\elul\trunk\elul\public/" 

<Directory "c:\wamp\www\elul\trunk\elul\public/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>

To a virtual host looking like :

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "C:\wamp\www\examen_fle\trunk\examen_fle\public"
    ServerName examen.elul.local
    ErrorLog "logs/your_own-error.log"
    CustomLog "logs/your_own-access.log" common
    <directory "C:\wamp\www\examen_fle\trunk\examen_fle\public">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </directory>
</VirtualHost>

Since it runs locally, i also had to edit the file hosts in C:\WINDOWS\system32\drivers\etc to add examen.elul.local in the file

127.0.0.1       examen.elul.local
4
  • 1
    This may be as simple as your http server isn't parsing the .htaccess file. Is the AllowOverride Apache setting set properly? Commented Nov 8, 2010 at 17:27
  • Is your mod_rewrite set up poperly? a2enmod rewrite to enable it + apache restart. Commented Nov 8, 2010 at 17:40
  • So far mod_rewrite is working (I get a not found error if i disable it) ans if have an alias pointing to my public folder. I will try this with a virtual host to see if it changes anything. Commented Nov 8, 2010 at 18:23
  • serverfault.com/questions/153745/… Commented Nov 8, 2010 at 21:45

1 Answer 1

1

If you prefer using an alias instead of a virtual host, you might want to use the RewriteBase or you may prepend the base url to the frontcontroller:

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

or

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

should work too... I use this one though:

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

It's a simpler rule but I'm not sure if it really affects the performance or covers all the possibilities.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, since I have enabled virtual host I will stick with my new config, but i will definately give your solution a go if I have to configure a new project.
I just had to setup my web app on a new server which is using alias to redirect urls to their final location and your solution worked like a charm (I used the first one)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.