0

我正在尝试从 url 隐藏 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。

4

3 回答 3

2

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

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

接下来,您必须AllowOverride All在 vhost 配置中进行设置,以确保 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. 因此,如果您输入域的根 URL 并被重定向到app.php它,可能是因为mod_rewrite.

于 2014-07-29T14:27:31.633 回答
0

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

RewriteCond %{THE_REQUEST} ^.*/app.php 
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)app.php/(.*)?$ /$2 [R=301,L]
于 2013-05-25T10:31:20.427 回答
-1

此处描述了您的问题的解决方案。

<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>
于 2013-05-24T14:46:53.940 回答