[英]Symfony2 project inside folder hide web/app.php just with .htaccess
I have help-desk project made using Symfony2 and I would like to host the project inside a folder in my website hiding the "web/app.php" from URL. 我有使用Symfony2创建的帮助台项目,我想将该项目托管在我的网站的某个文件夹中,该文件夹从URL中隐藏“ web / app.php”。 I can't create a virtual host with apache, so I will need to use .htaccess with RewriteRule and RewriteCond.
我无法使用apache创建虚拟主机,因此需要将.htaccess与RewriteRule和RewriteCond结合使用。 I'm reading and trying for 2 days without success.
我正在阅读并尝试2天,但均未成功。
I have the folder 'help' in the root directory of website. 我在网站的根目录中有文件夹“ help”。 Inside this folder I have the Symfony with the folders: app, src, vendor and web.
在此文件夹中,我拥有带有以下文件夹的Symfony:app,src,vendor和web。 'web' is the public folder that has the app.php controller that handle the resquests.
“ web”是具有用于处理请求的app.php控制器的公用文件夹。 So with the default .htaccess inside the web folder I can access the help-desk system by: www.example.com/help/web that the controller app.php catch the request and redirect to the route 'login' (www.example.com/help/web/login).
因此,使用Web文件夹中的默认.htaccess,我可以通过以下方式访问帮助台系统:www.example.com/help/web,控制器app.php捕获了请求并重定向到路由“登录”(www.example .com / help / web / login)。 I would like to access the system just with the URL: www.example.com/help
我只想使用以下网址访问系统:www.example.com/help
The original .htaccess inside web folder is: Web文件夹中的原始.htaccess文件是:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I've almost get what I need creating a .htacess inside the help folder with: 我几乎可以用以下方法在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>
And deleting the .htaccess inside web folder, so when I try www.example.com/help the URL doen't change and I know that the app.php inside web folder was accessed because of a 'echo' that I wrote in the code. 并删除Web文件夹中的.htaccess,因此当我尝试www.example.com/help时,URL不会更改,并且我知道访问了Web文件夹中的app.php是因为我在码。
The result is: 结果是:
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.
The 'String test' is a echo that I put inside the app.php (default code from Symfony framework): “字符串测试”是我放入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);
I think I am almost there But I don't know what I doing wrong. 我想我快到了,但是我不知道我做错了什么。
Make a entry in a .htaccess. 在.htaccess中进行输入。 Suppose you have a website abc.com.
假设您有一个网站abc.com。 You want to run another website in directory.
您要在目录中运行另一个网站。 Then create a .htaccess in parent directory pointed to abc.com
然后在指向abc.com的父目录中创建一个.htaccess
Folder Structure 资料夹结构
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.