views:

252

answers:

3

Is it possible to set the /web directory as webroot without changing apache configuration file?

I tried using the following .htaccess code, but if i go to localhost/module/, it displays 404 error. But if i go to localhost/web/module/ then everything works.

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    sf/(.*) lib/vendor/symfony/data/web/sf/$1 [L]
   RewriteRule    ^$ web/    [L]
   RewriteRule    (.*) web/$1 [L]
</IfModule>
A: 

Short answer: no.

Bit longer: you will have to edit the apache config at least to give it permission to access the web/ directory, so even if you symlink your web folder to /var/www, it will not work.

Maerlyn
My web directory path is /home/xx/public_html/web
aRagnis
Then why not make /home/xx/public_html your webroot? Put your code in /home/xx, and edit your ProjectConfiguration to call `$this->setWebDir`? If it works, I'll update my answer.
Maerlyn
i've put all my symfony files to /home/xx/private_html/ and left only /web folder contents to /home/xx/public_html/But now i can't get it working. Symfony is still looking for its files from /home/xx/public_html/ folder.
aRagnis
Put these in your ProjectConfiguration class: `$this->setWebDir("/home/xx/public_html/"); $this->setRootDir("/home/xx/private_html/");`I'm using something like this, but my symfony files are in /home/xx, and the webroot is /home/xx/public_html.
Maerlyn
It still tryes to find its files from public_html
aRagnis
I'm afraid I'm out of ideas.
Maerlyn
A: 

This is quiet similar to my question Symfony on virtual host (document root problem).

This is my .htaccess in the project root directory:

RewriteEngine On
RewriteBase /       

RewriteCond %{REQUEST_URI} ^/images/  [OR]
RewriteCond %{REQUEST_URI} ^/js/      [OR]
RewriteCond %{REQUEST_URI} ^/css/
RewriteRule ^(.*)$ /web/$1 [L]

RewriteCond %{REQUEST_URI} !^/web/
RewriteRule ^(.*)$ /web/index.php [QSA,L]

This solved my problem but symfony tries to generate every url (eg. using url_for) from the document root so instead of url like domain.com/my-article it generates domain.com/web/my-article.
I had to slightly modify my PatternRouting class to trim the /web prefix from each url. I think this is not the best solution but it works.

Also if I want to access backend application I have to call always /web/backend.php/ because I don't want to have so many rewrite rules in the .htaccess.

If you want to see my extended PatternRouting class source code I'll paste it here.

Martin Sikora
A: 

i do like this on the root :

RewriteEngine On
RewriteBase /
RewriteRule (.*) ./web/$1 [L]

And edit web/.htaccess uncommented the 'RewriteBase /' line.

this make all the mysite.com/aaaa/bbbb works like mysite.com/web/aaaa/bbbb

x2l2