Symfony 4 + Apache 2.4 + mod_rewrite无法正常工作 - php

我究竟做错了什么?

这是我在/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/number时,一切正常。

但是用http://hello-world/lucky/number我得到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”。我更改此行:

<Directory "/home/carlos/dev/github/hello-world/public"> 
# AllowOverride None 
# Order Allow,Deny 
Require all granted 
# Allow from All – 

...但我仍然得到500。

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

[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

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

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

现在可以了。

谢谢你们

Apache + PHP同时使用多个脚本 - php

美好的一天。首先,对不起我的英语不好=)所以。我创建了脚本:<? sleep(10); ?> 我的Apache有MPM模块,很明显我没有在此脚本中使用会话,只是..只是sleep(10)。当我在浏览器中同时打开2个标签时,第一个标签会在10秒内加载,第二个标签会在20秒内加载。但。当我同时在2个不同的浏览器中打开此脚本时,它将在10秒后加载到每个…

在Java中,执行“ ++++++++”表达式,编译器未报告任何错误并且可以正确执行? - java

我用eclipse编写了这段代码,用war写过,结果为3d。public static void main(String[] args) { double a = 5d + + + + + +-+3d; System.out.println(a); } 参考方案 您的表情可以改写为(5d) + (+ + + + +-+3d) 其中第一个+是应用于两个操作数的…

正则表达式,用于验证以+254开头的电话号码 - php

我正在尝试创建一个正则表达式以匹配以+254开头的电话号码电话号码示例 +254716370730+254856798768 +254765432135 我努力了preg_match('/^\\+254\\d{9}/,$phonenumber'); 但似乎无效,我们将不胜感激任何帮助 参考方案 正确的语法应为:preg_match(�…

Symfony 2在用户站点上动态添加字段以形成表单 - php

我正在研究调查包。目的是为用户提供一个功能全面的调查系统。我已经准备好一个后端,使您可以创建调查,添加问题(打开文本,单选按钮,复选框),是否需要提问,激活调查,生成令牌以及通过电子邮件将令牌发送到调查的链接。当然,我也有显示调查并保存答案的前端。现在,我想添加另一种可能性。带有答案(单选或复选框)和评论的问题。例如:你有一只狗吗?是没有如果用户选择是,则附…

PHP getallheaders替代 - php

我正在尝试从服务器上的apache切换到nginx。唯一的问题是我在PHP脚本中使用的getallheaders()函数,该函数不适用于Nginx。我已经尝试过用户在getallheaders函数上的php站点上提供的注释,但这并不返回所有请求标头。请告诉我如何解决这个问题。我真的想切换到Nginx。 参考方案 您仍然可以使用它,但是您必须像这里一样重新定义…