我有一个用apache2配置的子域xxx.yyy.fr
到文件夹/var/www/my_symfony_project/web/
默认情况下,symfony将所有其他查询重定向到/app.php
(/web目录中有.htaccess):
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/app.php [L]
因此,xxx.yyy.fr
被重定向到xxx.yyy.fr/app.php/
我有一个类似于xxx.yyy.fr/app.php/my_route/{optional_param}
的路线,有一个控制器和一个视图。
我的问题是:当我转到xxx.yyy.fr/{optional_param}
时,就像我转到完整的urlxxx.yyy.fr/app.php/my_route/{optional_param}
一样,我如何重写这个url?
谢谢!
你只有一条路线吗?
否则,它将始终重定向到您设置的路由。
我想你需要这样的东西。还有一件事。如果您将所有内容重定向到单个url,那么您的images/、js/、css/文件将无法工作。它们还将重定向。
你可以试试这样的东西。这是我目前使用的。
DirectoryIndex app.php
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^/web/app.php/your_route - [L]
# Fix the bundles folder
RewriteRule ^css/(.*)$ /web/css/$1 [QSA,L]
RewriteRule ^js/(.*)$ /web/js/$1 [QSA,L]
RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L]
RewriteRule ^fonts/(.*)$ /web/fonts/$1 [QSA,L]
RewriteRule ^images/(.*)$ /web/images/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ /web/app.php/your_route [QSA,L]
# RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>
您不需要/web部分,因为您已经重定向到/var/www/my_symfony_project/web/
希望这能帮助