【问题标题】:Always getting 404 error with SymfonySymfony 总是出现 404 错误
【发布时间】:2013-03-25 09:36:38
【问题描述】:

我是 Symfony 的初学者,但我无法使其正常工作。我在我的机器(ubuntu)上运行 apache 2。看来我可以通过 url 访问配置: 本地主机/Symfony/web/config.php

另外,我可以通过这个 url 访问主页: 本地主机/Symfony/web/app_dev.php (我看到的第一个消息是:加载 Web 调试工具栏时发生错误(404:未找到)。您要打开分析器吗?)。我唯一能做的就是取消(如果你尝试接受,我会收到 404 未找到)。

在那之后,没有任何效果。即便是 。始终找不到 404。

据我所知,这可能是缓存的问题,也可能是 apache 配置的问题。但是无论我尝试什么都不能解决问题(其他人在stackoverflow中提出了类似的问题,但对我来说没有任何解决方法)。

有人知道吗?提前致谢。

【问题讨论】:

  • 你有没有给777缓存和日志权限
  • suthar,你只是省略了 hello 字符 :)

标签: php ubuntu symfony apache2


【解决方案1】:

我以前也有这个问题,请看我的配置试试看

在我的 .htaccess 中:

大家好,我也遇到了这个问题。似乎“股票” .htaccess 是问题所在。我已经在我的环境中解决了这个问题,这是我的 .htaccess 和注释:

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

在 /etc/apache2/sites-available 中的“symfony”条目中:

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

【讨论】:

  • 对于未来的读者,我遇到了问题,我在 apache 配置中缺少“AllowOverride All”。
【解决方案2】:

请查看您的 .htaccess 或您的 appache 设置 (mod_rewrite)

看:Symfony 404 errors

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-25
    • 2017-07-07
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多