【问题标题】:Symfony urls without app.php没有 app.php 的 Symfony 网址
【发布时间】:2017-10-02 13:25:57
【问题描述】:

我在生产环境中有我的 symfony 应用程序,但我不明白为什么没有 app.php 它不能运行。例如,如果我使用 mydomainname,我可以看到主页,但其他路由进入错误 404 未找到,但如果我使用 app.php (mydomainname/app.php/register) 对其他路由进行数字化,它运行完美。 我的 httpd.conf 是:

ServerRoot "/etc/httpd"

Listen 80

LoadModule rewrite_module modules/mod_rewrite.so

Include conf.modules.d/*.conf

User myuser
Group psacln

ServerName mydomainname:80

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/vhosts/myexample.com/httpdocs/web"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>


<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf
GracefulShutDownTimeout 3
AddOutputFilter INCLUDES .shtml
AddType text/html .shtml
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<VirtualHost *:80>

        CustomLog /var/log/httpd/myexample.com-access.log combined
    ErrorLog /var/log/httpd/myexample.com-error.log
        ServerName myexample.com
    ServerAlias mydomainname
        DocumentRoot /var/www/vhosts/myexample.com/httpdocs/web
    <Directory /var/www/vhosts/myexample.com/httpdocs/web>
                DirectoryIndex app.php

        AllowOverride None
                Order Allow,Deny
                Allow from All
            <IfModule mod_rewrite.c>
                  Options -MultiViews
                  RewriteEngine On
                  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
                  RewriteRule ^ /app.php [L]
            </IfModule>

    </Directory>       
</VirtualHost>

在我的路径寄存器的error_log文件中,例如:

[Tue May 02 16:45:55.666829 2017] [rewrite:trace3] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d4006440/initial] applying pattern '^(.*)$' to uri '/register/', referer: h t t p s : //mydomainname/
[Tue May 02 16:45:55.666870 2017] [rewrite:trace4] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d4006440/initial] RewriteCond: input='mydomainname' pattern='^mydomain\\.com$' [NC] => not-matched, referer: h   t t p s : //mydomainname/
[Tue May 02 16:45:55.666886 2017] [rewrite:trace1] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d4006440/initial] pass through /register/, referer: h t t p s : //mydomainname/
[Tue May 02 16:45:55.670388 2017] [rewrite:trace2] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] init rewrite engine with requested uri /error_docs/not_found.html, referer: h   t  t p  s : //mydomainname/
[Tue May 02 16:45:55.670403 2017] [rewrite:trace3] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] applying pattern '^(.*)$' to uri '/error_docs/not_found.html', referer: h t t p s:// mydomainname/
[Tue May 02 16:45:55.670410 2017] [rewrite:trace4] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] RewriteCond: input='mydomainname' pattern='^mydomain\\.com$' [NC] => not-matched, referer: https://mydomainname/
[Tue May 02 16:45:55.670414 2017] [rewrite:trace1] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] pass through /error_docs/not_found.html, referer: https://mydomainname/

mod_rewrite 已打开,因为如果我运行 httpd -M 命令,则会出现以下行:

rewrite_module(共享)

我的服务器是:

服务器版本:Apache/2.4.6 (CentOS)

我能做些什么来解决它?

非常感谢。

【问题讨论】:

  • 谁能帮帮我?我只需要方向

标签: apache symfony1


【解决方案1】:

@Massimiliano

我曾经遇到过同样的问题。我通过在 web 文件夹中添加 .htaccess 文件来纠正。

尝试在 .htaccess 文件中添加此内容
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php/$1 [QSA,L] </IfModule>

REFERENCE LINK HERE.

还有这样的虚拟主机。

<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>

例如,如果我使用 mydomainname,我可以看到主页,但其他路由进入错误 404 未找到,但如果我使用 app.php 对其他路由进行数字化
=> 添加一个 .htaccess 文件,问题将得到纠正。

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2012-03-07
    相关资源
    最近更新 更多