I have the following .htaccess file in my web directory for my Symfony2 installation:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) app.php [QSA,L]
</IfModule>
However, when I try something basic such as:
(whatever)/web/app.php/place
it doesn't removing the app.php from the URL. I'm new to Apache and I'm not sure what's going on here, can anyone shed some light? Thanks in advance!
EDIT: Due to the structure of the web app I am working with I cannot move app.php or app_dev.php outside of the web folder nor can I modify the server configuration of Apache in anyway, thus I am looking for an alternative solution to this problem.
You must enable the rewrite module in Apache, as the "IfModule mod_rewrite.c" states.
To do so:
See http://www.lavluda.com/2007/07/15/how-to-enable-mod_rewrite-in-apache22-debian/.
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
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With