Symfony 2 removing app.php - php

i have been through lots of topic about this, and the thing is still not working so i was wondering if you could help me to see what i am doing wrong.
My goal is to have neat URL as www.name.com without the app.php nor web, and i have changed over and over my Virtualhost & Htacces that my page are kind of gone for now^^ (Yeah so pro)
So first, i have enabled the rewrite mod, and i am running a 2.2.2 apache version.
Here is my VirtualHost files :
<VirtualHost *:80>
ServerName steeph
ServerAlias name.com
DocumentRoot /home/ksc/www/symfony/web
<Directory /home/ksc/www/symfony/web>
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I have also tried with line on :
<Directory "path">
DirectoryIndex app.php
Options -Indexes
AllowOverride All
Allow from All
</Directory>
which are not working either
For my htaccess i have tried at the symfony files root (and removing the /web from the virtual host) which was a fail, and i tried with this htaccess
<IfModule mod_rewrite.c>
RedirectMatch permanent ^/app\.php/(.*) /$1
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I tried with the "RedirectMatch permanent ^/app.php/(.*) /$1" and without
So i have been to like a dozen of stackoverflows and i have tried even not popular answer but it still not working, so i would really appreciate some help here
Thanks a lot!

If Linux... enable Rewrite
sudo a2enmod rewrite
sudo service apache2 restart

You could just copy the one from symfony standard edition
-> https://github.com/symfony/symfony-standard/blob/master/web/.htaccess
and it would just work fine.

Related

Symfony (3.4) app : cant redirect requests to /web dir via .htaccess

I've a website lets say website.fr ( on server : /web/website ) ;
I ve added a symfony blog app in /web/website/blog/.
I dont manage to access the blog via website.fr/blog/ (404 error)
There is a .htaccess file in /web/website/blog/ directory, and one in /web/website/blog/web directory.
I am used to deploy symfony apps 'alone' on a server, and make the domain point to the web dir of the app, and everything always works fine, but in this configuration, I cant get it to work.
I have tried to use the following .htaccess conf under /web/website/blog/ :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And I did not edit the default one under /web/website/blog/web/
Im not sure what Im doing wrong, so any help would be appreciated !
For me I use .. nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
which is explained Here and restart Apache, but I do not know if I understand your problem
I couldn't get what I wanted, but here is the solution I implemented :
I created a .htaccess in /web/website dir, that rewrites all requests to /web/website/blog, with the root (/) excluded from this rewriting :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ blog/web/$1 [QSA,L]
</IfModule>
That's not the way I wanted to get my rewriting, but I have the result I expected ; note that it would not be a good solution for a website that would evolve with new modules, routes, folders...

Symfony 3, domain name shows Directory Structure

I know this question is asked a lot but I read all the questions related to this but they didn't solve my problem.
I just deployed a Symfony 3 web app and I followed the Symfony server configuration documentation just to find out that the www.domain.com displays the directory structure!
Here's the configuration that I used of file /etc/apache2/sites-available/site.com.conf:
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
I can see the app when I go to www.domain.com/web and www.domain.com/web/app.php
I want to be able to visit www.domain.com and see the app.
Change the line:
AllowOverride None
to next one:
AllowOverride All
Remove section <IfModule mod_rewrite.c> And use standard Symfony's .htaccess file.
Also you need to set up PHP as module for your apache. Be sure to have uncommented line in http.conf that loads PHP module:
LoadModule php7_module libexec/apache2/libphp7.so
You are missing your DirectoryIndex app.php or DirectoryIndex dev_app.php contained in your directory tag. This will cause apache to load app.php if a file has not been requested.
https://httpd.apache.org/docs/2.0/mod/mod_dir.html
<Directory /var/www/project/web>
DirectoryIndex app.php
...
</Directory>
Also make sure mod rewrite is enabled.
a2enmod rewrite
You may have to use sudo.
One final note:
Options -MultiViews should be contained inside the <Directory> for use all the time and not just when mod_rewrite is enabled.

URL Rewriting and Laravel 4 Routes not working on server?

I bet this question has been asked time and time again, but I just can't seem to get an answer. Anyway, here is my situation. I have a domain, lets say example.com. Example.com works fine, everything works as it should. However, if I navigate to Example.com/about, which works on my local machine, I get a 404 error. However, if I go to example.com/index.php/about, the about page works fine. I know this must be a mod rewrite issue. I have enabled mod rewrite and restarted my server to no avail. Anyway, here is some code:
Virtual Host:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/example/public"
<Directory "/var/www/example/public">
AllowOverride all
Allow from All
</Directory>
</VirtualHost>
And here is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm using Ubuntu 14.04 on a Digital Ocean Droplet.
Thanks!
1)
go to /etc/apache2/sites-available and create file and add below
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#newyear
DocumentRoot /var/www/html/example/public
<Directory /var/www/html/example/public>
options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
2) Create Link of above created file and paste it into /etc/apache2/sites-enabled
3) Check /etc/apache2/mods-available for rewrite.load file
if it is not there create it and add below line & save
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
create link of rewrite.load file and paste it into etc/apache2/mods-enabled
4) open /etc/hosts
add below
127.0.0.1 example.com
5) sudo service apache2 restart
I figured out how to do this, I had to put my VirtualHost code in sites-enabled, not sites-available. Facepalm.
In ubuntu 14.04 with apache2 i was fall this problem.Then i solve this and wrote a blog,you can follow this
http://www.kingpabel.com/apache-mod_rewrite/

Unable to access routes without index.php in Laravel 4

Ok, so I have spent a considerable amount of time googling for suggestions for this, and despite setting up several test project in Laravel 4 before on WAMPserver, I am not sure what I am missing in this case. Hopefully I have provided all details necessary on my setup and what I have tried so far.
WAMPserver version 2.4, located in C:/wamp/
Apache version 2.4.4
PHP version 5.4.12
mod_rewrite enabled (I can see it in phpinfo())
Project located in C:/wamp/www/wsrp/
in C:/wamp/www/wsrp/public I have the following .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
In my C:/wamp/bin/apache/Apache2.4.4/conf/httpd.conf file I have uncommented this line:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
In my C:/wamp/bin/apache/Apache2.4.4/conf/extra/httpd-vhosts.conf file I have the following:
<VirtualHost *:80>
DocumentRoot "C:\wamp\www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/wsrp/public"
ServerName localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www/wsrp/public">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
In my C:/wamp/www/wsrp/app/routes.php file I have this test route:
Route::get('test', function() {
echo 'Hello world!';
});
To test I am trying to visit this URL:
http://localhost/wsrp/test
And this doesn't work, it shows me an Internal Server Error page. If however I visit this URL:
http://localhost/wsrp/index.php/test
I see my 'Hello world!' message displayed.
Obviously I want to be able to work on this project without having the index.php in the URL, that is the problem.
Of all the SO questions/answers I have looked at, they have all suggested adding a virtual host, which I've done, having the right .htaccess file in C:/wamp/www/wsrp/public/ which I've done, having mod_rewrite enabled, which I've done and yeah.. not sure what else to try, or what I am missing. Help and suggestions greatly appreciated!
Edit:
Forgot to mention that I also have an alias file in C:/wamp/alias/wsrp.conf
Alias /wsrp "c:/wamp/www/wsrp/public"
<Directory "c:/wamp/www/wsrp/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
Firstly why do you have a localhost v-host? The root directory for WAMP servers is typically c:/wamp/www that is already mapped by HOSTS to 127.0.0.1 or localhost. That v-host is irrelevant.
Secondly, as your c:/wamp/www directory is being used to contain your sites, httpd.conf already contains the <Directory> details it needs, from memory it looks something like:
<Directory c:/wamp/www>
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
You don't need to define any special directory information for sub directories unless you want to add specific module configuration or change any of the defaults. To get your vhost working you need add no more than:
<VirtualHost *:80>
ServerName mylocalsite.dev
DocumentRoot c:/wamp/www/mysite/public
</VirtualHost>
I would suggest however that you put in locations for error logging / access logging.
I've had the same problem that you. I solved this problem in this way.
Open C:\wamp\bin\apache\Apache2.4.4\conf/httpd.conf
Then, You may search the next line, #LoadModule rewrite_module modules/mod_rewrite.so
Remove the pound ('#') sign at the start and save the file.
Next, restart your WampServer and test.
I hope help you!

How to remove "web/app_dev.php" from Symfony2 URLs?

I just created my first Symfony2 project. But the "/web/app_dev.php" part in the URL annoys me. It should be possible to do this without Virtual hosts...
But when I try this through .htaccess I always get routing errors and the "web/" is always added to the url...
EDIT: The whole project is also in a subdirectory named "symfonyTest". The Url to the demo page is "http://localhost/symfonyTest/web/app_dev.php/demo/" and it should become "http://localhost/symfonyTest/demo/". Links should also have this syntax. Is this possible?
Symfony2 comes with a built in debug mode, which is what you are using when you access url's with the app_dev.php addition. The debug mode caches significantly less than the production mode which can be accessed by directing your browser to the url, but leaving out the app_dev.php. If accessing this url doesn't work then it probably means that you need to clear your production cache.
To clear the cache direct you terminal (command console) to the root of you Symfony project. From there type the following command:
php app/console cache:clear --env=prod --no-debug
Per comments below in Symfony 3 this has moved:
php bin/console cache:clear --env=prod --no-debug
This should clear your productions cache and allow you to access urls without the app_dev.php.
As for the web part of the url. The easiest way to remove that is to set the web root of your project to the web folder. It's best to do this with apache using virtual hosts, but there are ways to do it with the htaccess.
This link explains how to use the htaccess file to change the webroot.
http://kb.siteground.com/how_to_change_my_document_root_folder_using_an_htaccess_file/
Hope this helps!
<VirtualHost *:80>
DocumentRoot "path_to_symfonyTest/web"
ServerName "symfonyTest"
<Directory "path_to_symfonyTest/web">
DirectoryIndex app_dev.php
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
RedirectMatch permanent ^/app_dev\.php/(.*) /$1
</Directory>
</VirtualHost>
That's part of my httpd.conf
I used to have this problem too, please take a look at my configurations and try them out
inside my .htaccess:
Hi all, I have been having this problem too. And it seems that the "stock" .htaccess is the problem. I have solved this in my environment and here is my .htaccess with notes:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
inside my "symfony" entry in /etc/apache2/sites-available:
<VirtualHost 127.0.1.15>
ServerAdmin webmaster#localhost
ServerName symfony
DocumentRoot /var/www/Symfony/web
DirectoryIndex app.php
<Directory /var/www/Symfony/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If you use an apache virtual host, you can get it working the way you desire. Here is an example virtual host from my xampp:
<VirtualHost *:80>
ServerName myurl.local
# Basic stuff
DocumentRoot "C:/path/to/symfony/web"
DirectoryIndex app.php
<Directory "C:/path/to/symfony/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
After restarting your apache, you can access the project through http://myurl.local (don't forget to configure your hosts file under C:\Windows\system32\drivers\etc\hosts!). If you want to have the dev environment (app_dev.php) not showing up in the url, change the DirectoryIndex to app_dev.php.
//enable mod rewrite
sudo a2enmod rewrite
Change all occurrences of AllowOverride None by AllowOverride All File: (/etc/apache2/apache2.conf) or (/etc/apache2/sites-available/000-default.conf) - for me work with /etc/apache2/apache2.conf file.
Example:
<Directory /var/www/web/>
# enable the .htaccess rewrites
Options Indexes FollowSymLinks
#AllowOverride None #commented
AllowOverride All
Require all granted
</Directory>
//Restart apache service: sudo service apache2 restart
You would need .htaccess file in parent folder of web, however, I wouldn't suggest doing so. That folder, apart from web, contains complete source, binaries, vendors and much more therefore you would need to apply many rules just to allow web-access to web folder and disallow web-access to everything else.
So, it's doable, but I would definitely go for vhost solution...
you just need to copy the content of .htaccess file to the your-website.conf
inside the TAG Directory

Categories