如何正确访问主页?

时间:2013-06-19 09:55:24

标签: apache symfony

我启用mod_rewrite但是当我转到主页时,浏览器尝试下载一些东西。当我转到app_dev.php时,浏览器显示错误:

The requested URL /app_dev.php/ was not found on this server.

我的语言环境主机已配置为网络目录。

'app / console router:debug _welcome'的输出是:

[router] Route "_welcome"
Name         _welcome
Path         /
Host         ANY
Scheme       ANY
Method       ANY
Class        Symfony\Component\Routing\Route
Defaults     _controller: Acme\DemoBundle\Controller\WelcomeController::indexAction
Requirements NO CUSTOM
Options      compiler_class: Symfony\Component\Routing\RouteCompiler
Path-Regex   #^/$#s

我的httpd-vhosts.conf:

<VirtualHost *:80>
ServerAdmin myemail@email.com
DocumentRoot "/var/www/symfony/hz.dev/web"
ServerName hz.dev
ServerAlias www.hz.dev
ErrorLog "/var/log/apache2/hz.dev-error_log"
CustomLog "/var/log/apache2/hz.dev-access_log" common
</VirtualHost>

我的网站/ .htaccsess

DirectoryIndex app.php

<IfModule mod_rewrite.c>
RewriteEngine On  
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>        
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>

1 个答案:

答案 0 :(得分:0)

请尝试使用.htaccess。这很简单,我在开发过程中使用它。

<IfModule mod_rewrite.c>
    RewriteEngine On

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

然后,您应该可以在http://example.com/访问Symfony而无需在网址中使用app_dev.php