Patrick Bass Patrick Bass - 5 months ago 25
PHP Question

.htaccess in Symfony2-based website

I've installed Piwik on the root of my Symfony2-based website (which should accessible at mywebsite.com/piwik/index.php) and I've tried to configure my .htaccess file so I can get around the 'No route found for "GET /piwik/index.php"' exception.

The problem is I am not good enough at configuring .htaccess, as a result I still get the above exception. Of course, I have to read tutorials. This is how I have tried to configure my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^piwik/ - [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>


Any suggestions ? Thanks in advance.

Answer

Symfony ships with this rewrite rule as a default in web/.htaccess:

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

So you should be able to drop the piwik/ directory within the web/ directory (thus, index.php will be [SymfonyAppRoot]/web/piwik/index.php) and access the page there.

By doing this, you allow Apache to serve /piwik/index.php before Symfony has a chance to get in the way.