2

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

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

我的语言环境主机被配置为 web 目录。

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

1 回答 1

0

试试这个 .htaccess 。很简单,我在开发的时候就用到了。

<IfModule mod_rewrite.c>
    RewriteEngine On

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

然后,您应该能够在http://example.com/访问 Symfony,而 URL 中没有 app_dev.php

于 2013-06-19T22:21:09.763 回答