【发布时间】:2013-08-25 13:22:05
【问题描述】:
我有使用 Symfony2 制作的帮助台项目,我想将项目托管在我网站的一个文件夹中,隐藏 URL 中的“web/app.php”。我无法使用 apache 创建虚拟主机,因此我需要将 .htaccess 与 RewriteRule 和 RewriteCond 一起使用。我正在阅读和尝试 2 天没有成功。
我在网站的根目录中有文件夹“帮助”。在这个文件夹中,我有 Symfony 和以下文件夹:app、src、vendor 和 web。 'web' 是具有处理请求的 app.php 控制器的公共文件夹。因此,使用 web 文件夹中的默认 .htaccess,我可以通过以下方式访问帮助台系统:www.example.com/help/web 控制器 app.php 捕获请求并重定向到路由“登录”(www.example .com/help/web/login)。我想通过 URL 访问系统:www.example.com/help
web文件夹内的原始.htaccess是:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
我几乎得到了在帮助文件夹中创建 .htacess 所需的内容:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/suportefloripa/web/app.php - [L]
RewriteRule ^bundles/(.*)$ /suportefloripa/web/bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /suportefloripa/web/app.php [QSA,L]
</IfModule>
并删除 web 文件夹内的 .htaccess,所以当我尝试 www.example.com/help 时,URL 不会改变,我知道 web 文件夹内的 app.php 是因为我的“回声”而被访问的写在代码里。
结果是:
String test
Oops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
“字符串测试”是我放在 app.php 中的回声(来自 Symfony 框架的默认代码):
<?php
echo "String test";
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
我想我快到了但我不知道我做错了什么。
【问题讨论】:
-
您访问的路线是否可用?似乎 Symfony2 应用程序正在抛出这个
404,因为在任何控制器中都没有匹配的路由 -
我现在已更改为 app_dev.php,因此它会在错误中返回更多详细信息。它返回带有
No route found for "GET /help/"的开发页面,所以这是错误的,因为应该到达“/”以匹配我的项目的路由。另一个问题是由于这个错误的路径,css文件没有加载。
标签: php apache .htaccess symfony mod-rewrite