1

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.

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

The original .htaccess inside web folder is:

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

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

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

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

2
  • Is the route you access available? It seems like the Symfony2 application is throwing this 404 because there is no matching route in any controller Commented Aug 22, 2013 at 17:11
  • I've changed now to app_dev.php so it return more details in the error. It is returning the dev page with No route found for "GET /help/" so it is wrong because should arrive "/" to match in the routing of my project. Another problem is that the css files are not loading because of this wrong path. Commented Aug 22, 2013 at 19:09

1 Answer 1

2

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

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]
Sign up to request clarification or add additional context in comments.

1 Comment

I've tried your code applying to the example above inside the "help" folder without success: RewriteEngine on RewriteCond %{HTTP_HOST} ^example.com/help$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com/help$ RewriteCond %{REQUEST_URI} !help/web/ RewriteRule (.*) /help/web/$1 [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.