[英]Symfony2 project inside folder hide web/app.php just with .htaccess
我有使用Symfony2创建的帮助台项目,我想将该项目托管在我的网站的某个文件夹中,该文件夹从URL中隐藏“ web / app.php”。 我无法使用apache创建虚拟主机,因此需要将.htaccess与RewriteRule和RewriteCond结合使用。 我正在阅读并尝试2天,但均未成功。
我在网站的根目录中有文件夹“ help”。 在此文件夹中,我拥有带有以下文件夹的Symfony:app,src,vendor和web。 “ web”是具有用于处理请求的app.php控制器的公用文件夹。 因此,使用Web文件夹中的默认.htaccess,我可以通过以下方式访问帮助台系统:www.example.com/help/web,控制器app.php捕获了请求并重定向到路由“登录”(www.example .com / help / web / login)。 我只想使用以下网址访问系统:www.example.com/help
Web文件夹中的原始.htaccess文件是:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
我几乎可以用以下方法在help文件夹中创建一个.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);
我想我快到了,但是我不知道我做错了什么。
在.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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.