mod_rewrite:在Symfony2中的URL中重写环境 [英] mod_rewrite: rewriting environment in url in Symfony2
本文介绍了mod_rewrite:在Symfony2中的URL中重写环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Symfony2中创建了一个名为demo
的新环境,该环境由app_demo.php
控制.
I created a new environment in Symfony2 called demo
which is controlled by app_demo.php
.
我想使用htaccess重写网址:
I want to rewrite the url using htaccess tu use:
http://myhost/demo/
代替
http://myhost/app_demo.php/
我应该将哪个RewriteRule添加到我的.htaccess?
Which RewriteRule should i add to my .htaccess?
我已经在使用用户janek建议的方式从网址中删除app.php.但是,当我为app_demo.php添加这套规则时,我仍然得到404:
I was already using the way user janek suggests for removing the app.php from the url. But when i add this set of rules for the app_demo.php i still get 404:
DirectoryIndex app_demo.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app_demo\.php(/(.*)|$) %{ENV:BASE}/demo/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_demo.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^demo/$ /app_demo.php/
</IfModule>
</IfModule>
推荐答案
http://pastebin.com/JnvSGhvv标准symfony .htaccess,其中app.php替换为app_dev.php
http://pastebin.com/JnvSGhvv standard symfony .htaccess with replaced app.php to app_dev.php
这篇关于mod_rewrite:在Symfony2中的URL中重写环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文