文件夹内的Symfony2项目仅使用.htaccess隐藏web/app.php
我有一个使用Symfony2制作的帮助台项目,我想把这个项目放在我网站的一个文件夹中,从URL中隐藏“web/app.php”。我无法使用apache创建虚拟主机,因此我需要使用带有RewriteRule和RewriteCond的.htaccess。我阅读和尝试了两天,都没有成功 我在网站的根目录中有“help”文件夹。在这个文件夹中,我有一个带有文件夹的符号:app、src、vendor和web“web”是一个公用文件夹,其中包含处理重新请求的app.php控制器。因此,使用web文件夹中的default.htaccess,我可以通过以下方式访问帮助台系统:www.example.com/help/web,控制器app.php捕获请求并重定向到“login”(www.example.com/help/web/login)路由。我只想通过URL访问系统:www.example.com/help web文件夹中的原始.htaccess是:文件夹内的Symfony2项目仅使用.htaccess隐藏web/app.php,php,apache,.htaccess,symfony,mod-rewrite,Php,Apache,.htaccess,Symfony,Mod Rewrite,我有一个使用Symfony2制作的帮助台项目,我想把这个项目放在我网站的一个文件夹中,从URL中隐藏“web/app.php”。我无法使用apache创建虚拟主机,因此我需要使用带有RewriteRule和RewriteCond的.htaccess。我阅读和尝试了两天,都没有成功 我在网站的根目录中有“help”文件夹。在这个文件夹中,我有一个带有文件夹的符号:app、src、vendor和web“web”是一个公用文件夹,其中包含处理重新请求的app.php控制器。因此,使用web文件夹中的d
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
“字符串测试”是我放在app.php中的一个回音(Symfony framework中的默认代码):
在.htaccess中创建一个条目。假设你有一个网站abc.com。您想在目录中运行另一个网站。然后在指向abc.com的父目录中创建.htaccess
文件夹结构
abc.com->index.php
->symfony(symfony folder)->app
->src
->web
->vendor
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.abc.com$
RewriteCond %{REQUEST_URI} !symfony/web/
RewriteRule (.*) /symfony/web/$1 [L]
你所走的路线有空吗?Symfony2应用程序似乎抛出了这个404
,因为在任何控制器中都没有匹配的路由。我现在改为app_dev.php,因此它会在错误中返回更多详细信息。它返回的dev页面中没有找到“GET/help/”
的路由,因此它是错误的,因为应该到达“/”以匹配我的项目的路由。另一个问题是css文件没有加载,因为路径错误。我在“help”文件夹中尝试了将您的代码应用于上面的示例,但没有成功:RewriteCond%{HTTP\u HOST}^example.com/help$[NC,或]RewriteCond%{HTTP\u HOST}^www.example.com/help$RewriteCond%{REQUEST\u URI}!help/web/RewriteRule(.*)/help/web/$1[L]
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.
<?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);
abc.com->index.php
->symfony(symfony folder)->app
->src
->web
->vendor
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.abc.com$
RewriteCond %{REQUEST_URI} !symfony/web/
RewriteRule (.*) /symfony/web/$1 [L]