Apache 中的 RewriteRule 与 Symfony2 不删除 app.php [英] RewriteRule in Apache with Symfony2 not removing app.php

查看:20
本文介绍了Apache 中的 RewriteRule 与 Symfony2 不删除 app.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Web 目录中有以下 .htaccess 文件用于我的 Symfony2 安装:

I have the following .htaccess file in my web directory for my Symfony2 installation:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*) app.php [QSA,L]
</IfModule>

但是,当我尝试一些基本的东西时,例如:

However, when I try something basic such as:

(whatever)/web/app.php/place

它不会从 URL 中删除 app.php.我是 Apache 的新手,我不确定这里发生了什么,有人能解释一下吗?提前致谢!

it doesn't removing the app.php from the URL. I'm new to Apache and I'm not sure what's going on here, can anyone shed some light? Thanks in advance!

由于我正在使用的 Web 应用程序的结构,我无法将 app.php 或 app_dev.php 移动到 Web 文件夹之外,也无法以任何方式修改 Apache 的服务器配置,因此我正在寻找此问题的替代解决方案.

Due to the structure of the web app I am working with I cannot move app.php or app_dev.php outside of the web folder nor can I modify the server configuration of Apache in anyway, thus I am looking for an alternative solution to this problem.

推荐答案

该重写规则并不是要从 URL 中删除 app.php.它的目的是为每个请求使用 app.php如果请求 URL 不对应于真实文件.由于 app.php 是一个真实的文件,它将用于处理请求.

That rewrite rule is not meant to remove app.php from the URL. It's purpose is to use app.php for every request, if a request URL doesn't correspond to a real file. Since app.php is a real file, it will be used to serve a request.

如果你想去掉 web/app.php 部分,首先创建一个指向 web 文件夹的虚拟主机:

If you want get rid of web/app.php part, first create a virtual host pointing to the web folder:

<VirtualHost *:80>
    ServerName whatever
    DocumentRoot /path/to/project/web
</VirtualHost>

这将删除 web 部分.

然后,要删除 app.php 部分,请将其添加到 web/.htaccess 文件的开头:

Then, to remove the app.php part, add this to the beginning of the web/.htaccess file:

RedirectMatch permanent ^/app\.php/(.*) /$1

这篇关于Apache 中的 RewriteRule 与 Symfony2 不删除 app.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆