I have the following .htaccess file in my web directory for my Symfony2 installation:
RewriteEngine On
RewriteCond %{R
I had this problem today and the fix was to append a /$1 at the end of the url rewrite rule.
My .htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php/$1 [QSA,L]
</IfModule>
And the virtual host is defines as this:
<VirtualHost *:80>
DocumentRoot /var/www/html/symfony_site/web
DirectoryIndex app.php
<Directory /var/www/html/symfony_site/web >
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I managed to remove web/app.php part on my shared server.
RewriteEngine on RewriteBase / RewriteRule ^css/(.*) web/css/$1 RewriteRule ^images/(.*) web/images/$1 RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L]
I used RewriteCond on css and images as they still lie inside /web/ directory so all request to css and images will be routed to web/css and web/images directories respectively.
It worked well for me.
When you write RewriteCond %{REQUEST_FILENAME} !-f
you say "Don't change real files... they should still be reachable." If you remove that, it should work.
The reason for it allowing that is some frameworks let you use http://site.tld/script.php/abc=123&def=456 style of links.
If you want it to allow filenames except app.php, you could add that as another RewriteCond
.
We've been struggling with that as well. There are two solutions:
/web/
subfolder (as per Symfony2 guidance)app.php
and app_dev.php
outside of the /web/
subfolder, then update .htaccess
and include paths in both files accordingly (i.e. remove web/
to correct all paths after you've manually moved the files one folder above)(Note: cannot provide examples from vanilla installation of S2, since symfony.com seems to be down at the moment.)
I just got the same issue and I fixed it like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
That rewrite rule is not meant to remove app.php
from the URL. It's purpose is to use app.php
for every request, if a request URL doesn't correspond to a real file. Since app.php
is a real file, it will be used to serve a request.
If you want get rid of web/app.php
part, first create a virtual host pointing to the web
folder:
<VirtualHost *:80>
ServerName whatever
DocumentRoot /path/to/project/web
</VirtualHost>
This will remove the web
part.
Then, to remove the app.php
part, add this to the beginning of the web/.htaccess
file:
RedirectMatch permanent ^/app\.php/(.*) /$1