Symfony 4 + Apache 2.4 + mod_rewrite无法正常工作 [英] Symfony 4 + Apache 2.4 + mod_rewrite not working

查看:136
本文介绍了Symfony 4 + Apache 2.4 + mod_rewrite无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么错了?

这是我在/etc/apache2/sites-enabled/hello-world.conf上的配置

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>

当我尝试访问 http://hello-world/index.php/lucky/数字都正确.

但是使用 http://hello-world/lucky/number 时,我得到了404 Not Found

But with http://hello-world/lucky/number I get a 404 Not Found.

404错误是由于我配置了两个VirtualHosts. /etc/apache2/sites-enabled/000-default.conf 中的一个,/etc/apache2/sites-enabled/hello-world.conf 中的另一个.我在 000-default.conf 中将其删除,现在收到"500 Internal Server Error".我更改此行:

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 – 

...但是我仍然可以得到500.

...but still I'm getting the 500.

在/var/log/apache2/project_error.log上,显示以下消息:

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.

推荐答案

好,最后我得到了:

这是一个错误的配置:

    <IfModule mod_rewrite.c>
        Options -MultiViews
        RewriteEngine On
        # RewriteCond %{REQUEST_FILENAME} !-f
        # RewriteRule ^(.*)$ index.php [QSA,L]
        FallbackResource "index.php"
    </IfModule>

我一直在关注这里所说的话: https://httpd.apache .org/docs/2.4/rewrite/remapping.html

I was following what is said here: https://httpd.apache.org/docs/2.4/rewrite/remapping.html

但是后来我尝试不使用这个FallbackResource,回到Symfony文档给我的东西,

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>

现在可以正常工作了.

谢谢大家

这篇关于Symfony 4 + Apache 2.4 + mod_rewrite无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆