<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/mod_rewrite/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/mod_rewrite"/>
 <updated>2012-04-07T22:42:44-07:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>symfony + mod_rewrite: moving smoothly from development to production environments</title>
   <link href="http://davedash.com/2007/08/14/symfony-mod_rewrite-moving-smoothly-from-development-to-production-environments/"/>
   <updated>2007-08-14T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/08/14/symfony-mod_rewrite-moving-smoothly-from-development-to-production-environments</id>
   <content type="html">&lt;p&gt;I think a common problem for some symfony developers that aren't too familiar
with Apache's Mod Rewrite is when they move from a development environment that
uses an explicit controller (e.g. &lt;code&gt;frontend_dev.php&lt;/code&gt; is requested from the
server explicitly) to their production app which implicitly calls &lt;code&gt;index.php&lt;/code&gt;
(e.g. '/' or some other route is passed to &lt;code&gt;index.php&lt;/code&gt;) things stop working.&lt;/p&gt;

&lt;p&gt;This is probably a &lt;code&gt;mod_rewrite&lt;/code&gt; issue.  Mod Rewrite handles implicitly
directing (almost) all traffic to &lt;code&gt;index.php&lt;/code&gt; in a symfony application.&lt;/p&gt;

&lt;p&gt;The default &lt;code&gt;.htaccess&lt;/code&gt; for symfony is defined as such:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Options +FollowSymLinks +ExecCGI

&amp;lt;IfModule mod_rewrite.c&amp;gt;
  RewriteEngine On

  # uncomment the following line, if you are having trouble
  # getting no_script_name to work
  #RewriteBase /

  # we skip all files with .something
  RewriteCond %{REQUEST_URI} \..+$
  RewriteCond %{REQUEST_URI} !\.html$
  RewriteRule .* - [L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
&amp;lt;/IfModule&amp;gt;

# big crash from our front web controller
ErrorDocument 500 &quot;&amp;lt;h2&amp;gt;Application error&amp;lt;/h2&amp;gt;symfony application failed to start properly&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see if the &lt;code&gt;mod_rewrite.c&lt;/code&gt; module is not enabled this will not work.&lt;/p&gt;

&lt;p&gt;Luckily most packages of Apache have the module, it just needs to be enabled by uncommenting the right line of &lt;code&gt;.htaccess&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;LoadModule rewrite_module     libexec/httpd/mod_rewrite.so
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Restarting apache should give you full rewrite control.  This is fairly basic Apache administration, but for a lot of people symfony is their first foray into URL rewriting.&lt;/p&gt;
</content>
 </entry>
 

</feed>

