我在Windows 7上使用WAMP。每当我尝试创建虚拟主机以使用Symfony2项目的“干净”URL时,我都会收到404错误。
这是我的httpd.conf:
NameVirtualHost localhost
<VirtualHost localhost>
DocumentRoot "D:/Documents/wamp/"
ServerName localhost
</VirtualHost>
<VirtualHost my-project.local>
ServerName my-project.local
DocumentRoot "D:/Documents/wamp/my-project/web/"
DirectoryIndex app.php
<Directory "D:/Documents/wamp/my-project/web/">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
我的主人档案:
127.0.0.1 my-project.local
当我尝试访问http://my-project.local时,出现Symfony 404错误。当我查看http://my-project.local/app.dev时,我被重定向到http://my-project.local,因此我也收到了404错误,最后,当我尝试访问http://my-project.local/app_dev.php时,加载了正确的页面,但绝对没有CSS。
我还尝试将DirectoryIndex app.php
替换为DirectoryIndex app_dev.php
但我仍然获得404。
例如,当我为Laravel支持的其他项目创建虚拟主机时,我没有任何问题。
答案 0 :(得分:3)
示例VirtualHost 1)
<VirtualHost *:80>
ServerName yourproject.com
DocumentRoot "C:/xampp/htdocs/yourproject/web"
DirectoryIndex app_dev.php
<Directory "C:/xampp/htdocs/yourproject/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app_dev.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
VirtualHost示例2)
阅读更多信息:Symfony 2 on virtual hosts
<VirtualHost *:80>
ServerName www.domain.com.localhost
ServerAlias domain.com.localhost
ServerAdmin webmaster@localhost
DocumentRoot /home/user/www/project/web
<Directory /home/user/www/project/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
答案 1 :(得分:1)
对于Symfony 4:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot "c:/wamp64/www/symfony4_mysite/public/index.php"
<Directory "c:/wamp64/www/symfony4_mysite/public/index.php">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
答案 2 :(得分:0)
如果你检查web/.htaccess
,你必须为apache启用mod_rewrite,否则回退到app.php / app_dev.php。所以检查这个模块是否已加载到您的wamp中。
对于资产,您必须安装它们。在终端:
cd D:/Documents/wamp/my-project/
php app/console assets:install
此命令必须将资产包硬拷贝到web
目录,尝试使用--symlink
作为符号目录