问题
What am I doing wrong?
This is my config on /etc/apache2/sites-enabled/hello-world.conf
<VirtualHost *:80>
ServerName hello-world
DocumentRoot "/home/carlos/dev/github/hello-world/public"
<Directory "/home/carlos/dev/github/hello-world/public">
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</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>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/project/public/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
When I try to access http://hello-world/index.php/lucky/number all goes right.
But with http://hello-world/lucky/number I get a 404 Not Found.
The 404 error was due I had configure two VirtualHosts. One in /etc/apache2/sites-enabled/000-default.conf and other in /etc/apache2/sites-enabled/hello-world.conf. I removed that in 000-default.conf, and now I'm receiving a "500 Internal Server Error". I change this lines:
<Directory "/home/carlos/dev/github/hello-world/public">
# AllowOverride None
# Order Allow,Deny
Require all granted
# Allow from All –
...but still I'm getting the 500.
On /var/log/apache2/project_error.log there's this message:
[Thu Apr 05 19:56:25.819680 2018] [core:error] [pid 4277] [client 127.0.0.1:38800] AH00125: Request exceeded the limit of 10 subrequest nesting levels due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
回答1:
This is possibly caused due to a bug in Apache for versions prior to Apache 2.4.18.
There was an Apache bug with FallbackResource when being called on the home page causing Apache to hang.
The Apache bug details can be found here: https://bz.apache.org/bugzilla/show_bug.cgi?id=58292
I've added a PR to update the Symfony docs
回答2:
Ok, finally I got:
It was a misconfiguration here:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^(.*)$ index.php [QSA,L]
FallbackResource "index.php"
</IfModule>
I was following what is said here: https://httpd.apache.org/docs/2.4/rewrite/remapping.html
But then I tried to do without this FallbackResource, back to what Symfony documentation gave me, with this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
# FallbackResource "index.php"
</IfModule>
Now it's working.
Thank you all
回答3:
If you use Linux:
$ [sudo] a2enmod rewrite
回答4:
If you are using apache 2.4, have mod_rewrite already enabled, and getting something like the below in your virtualhost error log file:
[Thu Apr 05 15:08:55.619587 2018] [authz_core:error] [pid 2382] [client 10.0.1.1:51436] AH01630: client denied by server configuration: /vagrant/public/
Then update your virtual host and replace:
Order Allow,Deny
Allow from All
with
Require all granted
Also be sure to update /var/www/project/public/bundles to your actual directory.
来源:https://stackoverflow.com/questions/49664091/symfony-4-apache-2-4-mod-rewrite-not-working