symfony2 .htaccess从网址隐藏app.php

时间:2013-05-24 13:02:48

标签: .htaccess symfony url-rewriting

我正在尝试从网址隐藏app.php

我有:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]

哪个有效......但是当用户访问时

domain.com/app.php/Home/

比网址还要

domain.com/app.php/Home/

我希望只有

domain.com/Home

如何解决?

我试过了:

#RewriteCond %{THE_REQUEST} ^.*/app.php
#RewriteRule ^(.*)app.php/(.*)?$ /$2 [R=301,L]

我需要哪些工作,但当我做一些动作动态jquery ajax动作时,我得到错误405.

3 个答案:

答案 0 :(得分:2)

好像你没有启用mod_rewrite。你必须在你的机器上做:

  • sudo a2enmod rewrite(如果您没有a2enmod,则以其他方式启用模块)
  • service apache2 restart/etc/init.d/apache2 restart

接下来,您必须在vhost配置中设置AllowOverride All,以确保Symfony的web/.htaccess能够正确捕获网址。


其他信息:在Symfony的web/.htaccess

<IfModule !mod_rewrite.c> <IfModule mod_alias.c> # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. RedirectMatch 302 ^/$ /app.php/ # RedirectTemp cannot be used instead </IfModule> </IfModule>

如果未启用mod_rewrite,则apache会使用mod_alias通过app.php传递所有请求。因此,如果您输入域名的根网址,并且您被重定向到app.php,则可能是因为mod_rewrite

答案 1 :(得分:0)

我写了这样的东西,但我不确定它是否是一个好的解决方案?

RewriteCond %{THE_REQUEST} ^.*/app.php 
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)app.php/(.*)?$ /$2 [R=301,L]

答案 2 :(得分:-1)

问题的解决方案描述为here

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^app_dev.php - [L]
    RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    #RewriteRule ^(.*)$ app.php [QSA,L]
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
相关问题