文件夹内隐藏网/ app.php只需用的.htaccess Symfony2的项目文件夹、只需用、项目、app

2023-09-02 11:41:05 作者:相思树下相思赋

我有帮助台项目使用Symfony2的,我想举办一个文件夹内的项目在我的网站从隐藏URL中的网络/ app.php进行。我无法创建与Apache虚拟主机,所以我将需要使用的.htaccess与重写规则和的RewriteCond。我在读书,并努力2天都没有成功。

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. I can't create a virtual host with apache, so I will need to use .htaccess with RewriteRule and RewriteCond. I'm reading and trying for 2 days without success.

我的文件夹帮助在网站的根目录下。在此文件夹我有Symfony的的文件夹:应用程序,SRC,供应商和网络。 网络是具有app.php控制器处理resquests公用文件夹。因此,与网络文件夹中的默认的.htaccess我可以通过访问帮助台系统:www.example.com/help/web控制器app.php赶上请求,并重定向到路线'登录'(www.example .COM /咨询/网络/登录)。我想访问系统刚刚与网址:www.example.com/help

I have the folder 'help' in the root directory of website. Inside this folder I have the Symfony with the folders: app, src, vendor and web. 'web' is the public folder that has the app.php controller that handle the resquests. 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). I would like to access the system just with the URL: www.example.com/help

Web文件夹内的原有的.htaccess是:

The original .htaccess inside web folder is:

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

我已经几乎得到什么,我需要在创建Help文件夹内的.htacess有:

I've almost get what I need creating a .htacess inside the help folder with:

<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>

和删除网络文件夹内的.htaccess,所以当我尝试www.example.com/help网址doen't变化,我知道,网页文件夹内的app.php被访问,因为一个回响,我写在code。

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.

结果是:

    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的框架默认code):

The 'String test' is a echo that I put inside the app.php (default code from Symfony framework):

<?php

echo "String test";

use SymfonyComponentClassLoaderApcClassLoader;
use SymfonyComponentHttpFoundationRequest;

$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.

推荐答案

请在htaccess的一个条目。假设你有一个网站abc.com。你想运行目录另一个网站。然后创建父目录的.htaccess指向abc.com

Make a entry in a .htaccess. Suppose you have a website abc.com. You want to run another website in directory. Then create a .htaccess in parent directory pointed to abc.com

文件夹结构

   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]