Symfony 404错误

时间:2012-01-13 17:35:41

标签: php mysql symfony1 doctrine

在我的本地机器上,我创建的symfony项目完美无缺。

我已经在我的测试服务器上安装了symfony,它运行正常。当我在浏览器中访问URL时,我得到了#34; Symfony Project Created"页。我运行了check_configuration.php,一切都结束了。

我遇到的问题是:我创建了数据库并上传了表数据。我已经使用FTP将文件从本地计算机上传到服务器。当我尝试访问我创建的模块时,它会抛出404错误:

未找到

The requested URL /mymodule was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

以下是一些例子:

在使用MAMP的本地计算机上,我使用以下可正常工作的URL:

http://localhost:8080/frontend_dev.php/mymodule

我上传完所有内容后,如果我转到测试服务器网址:

http://my.url.com:8090/

我得到了"项目成功"带有/ sf图像和样式的页面。

但是如果我尝试

http://my.url.com:8090/mymodule

我收到404错误,好像该页面不存在,这让我觉得smfony不知道前端模块。

任何帮助?

2 个答案:

答案 0 :(得分:11)

你需要做两件事:

1)确保在Apache中启用了mod_rewrite。

2)仔细检查文档根目录中的.htaccess文件,确保其指向app.php。有点像:

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

答案 1 :(得分:3)

我曾经遇到过这个问题,请查看我的配置然后试试看

在我的.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>
</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>