如果您的 httpd.conf 说允许覆盖
NameVirtualHost *:80
<VirtualHost *:80>
ServerName foo.localhost.com
DocumentRoot "/Projects/YourProject/web"
<Directory "/Projects/YourProject/web">
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
你可以使用这个 web/.htacces
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app.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_dev.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
确保 ifmodule 已启用;关联
因此,在您的产品环境中,您将 app_dev.php 替换为 app.php
您可能还希望为每个环境设置不同的参数,最好的做法是将其放入 .gitignore 并创建两个文件:
parameters.prod.yml
parameters.dev.yml
并且根据阶段,您可以在同一目录中创建一个带有符号链接的 parameters.yml 文件,例如:
ln -s parameters.dev.yml parameters.yml