[英]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.