views:

387

answers:

3

Hello, I'm developing an application in Symfony and on localhost (XAMPP) I want to simulate the same conditions as on the webserver.

The web server is configured as follows:

/www   => mydomain.com
/foo   => foo.mydomain.com
/bar   => bar.mydomain.com
...

I'm going to put my Symfony application into /www direcotry so there'll be:

/www
/www/apps
/www/apps/frontend
/www/apps/frontend/...
/www/apps/backend
/www/apps/backend/...
/www/cache
/www/config
... and so on...
/www/web

The thing is that the document root is still set to the /www directory but Symfony expects it in the /www/web.
Of course it will work if I call http://mydomain.com/web but I guess you understand this is quiet stupid solution.

So my question is: Is there any way how can I change/bypass the default document root setting using .htaccess or whatever?

+2  A: 

I don't know much about Symfony but /web is supposed to be the document root. All the other directories should be outside the document root for security reasons for one, and to avoid the /web part in the URL for another. But it looks like you already know that.

If you can edit the web server's configuration, try to reflect that and set DocumentRoot to the web directory.

If you can't do that: It's not possible to change the DocumentRoot in a .htaccess file but it is possible to rewrite all requests so they go to /web internally using mod_rewrite. It's kludgy, but probably the best solution if you can't influence DocumentRoot.

I'm not a mod_rewrite guru so I can't provide an example (I would have to test it first and I can't do that right now) but I'm sure somebody will. Maybe add the mod_rewrite tag to your question.

Update: Untested but should work. Put into a .htaccess file in /www:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/web/ 
RewriteRule .* /web/%1 [QSA]

you would then need to change your configuration files to use http://www.domain.com/ instead of http://www.domain.com/web/ of course.

I can't say whether that interferes with any other .htaccess rules on the Symfony end - you'd have to try out.

Pekka
Thanks for your solution. It really works! But unfortunately only for http://www.domain.com/ or http://www.domain.com/blah. But it doesn't work for http://www.domain.com/backend.php and I can't figure out why. If I try http://www.domain.com/web/backend.php it works .
Martin Sikora
A: 

I you got hand on apache config, the better is to move document root from /www to /www/web in you virtualHost config and allow php (if restricted by open_basedir configuration directive) to access the whole /www directory.

Benoit
That's exactly what I can't. I've never seen any shared webhosting where you can modify apache config :)
Martin Sikora
Ok what we have done once with a shared host is to remove the public web dir, put all sf project in the shared host root, then recreate the www dir with a symlink targeting to web/ directory, but dunno if you can add symlinks or not
Benoit
A: 

Change the way symfony expects your directory to be named :

// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->setWebDir($this->getRootDir().'/www/or/whatever/directory');
  }
}
Clement Herreman