How to run Zend Framework with no .htaccess file.
Work has been overwhelming lately and frustrating but there was an interesting question asked by one of the developers at work. Can the Zend Framework run without the .htaccess file? The answer, Yes.
Why do we need the .htaccess file
First off why is the .htaccess file required in the first place by Zend Framework? Think of the .htaccess file as a funnel.
In a funnel, you poor water/liquid/stuff into the end contaning the larger diameter. The “stuff” is then squeezed out of a small single point at the opposite end. In the web world the “stuff” is web traffic and the the single point is where all the traffic goes through, in this case its the .htaccess file.
The .htaccess file will send all incoming traffic to your Front Controller which handles routing and dispatching etc.
Removing .htaccess from the process.
For this im going use Apache 2.2. Start off by opening up the httpd.conf file located in the the conf folder of your Apache installation. Somewhere near the bottom add the following lines.
#Application Specific Include file
Include conf/extra/httpd-zf.conf
This will allow Apache to add addition configuration settings once Apache is restarted and its a great place to isolate application specific Apache settings.
Now, go ahead an create the include file, “httpd-zf.conf” inside the APACHE_HOME/conf/extra/ directory and place the ReWrite rules which were originally in your .htaccess file into
it. Hit save, remove the .htaccess file, and restart Apache. You should see your Zend Framework application running.
Why do this?
Speed. Your application must always read the .htaccess file when someone visits the site. Removing this extra layer and placing it into the Web Server itself will reduce the amount of time a page loads.
Hope that helps someone out there 🙂