14

I want to access my symfony app in production env (http://www.sample.com/amateur1/web/app.php) from this url http://www.sample.com/amateur1.

To do that I moved the .htacces file to http://www.sample.com/amateur1/.htaccess with this contents:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /web/

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

But when I go to http://www.sample.com/amateur1 shows a 404 Error, and prod.log isn't written.

I also used RewriteBase /amateur1/web/ because I don't know If RewriteBase path is relative to the DocumentRoot of the server, Or from the path where the .htaccess file is located. Also tried /amateur1 and /amateur1/ as RewriteBase due to this answer Symfony2: How to deploy in subdirectory (Apache)

With the three try's, The Exceptions page appears unstyled, and not loading any image. But then I get the following error in prod.log file:

[2013-02-15 02:06:47] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /amateur1/" (uncaught exception) at /home/u105859802/public_html/amateur1/app/cache/prod/classes.php line 5121 [] []

What I'm doing wrong ?

Community
  • 1
  • 1
Jeflopo
  • 2,192
  • 4
  • 34
  • 46

2 Answers2

24

In your configuration, apache uses public_html as the document root

If Symfony2 is installed in directory /home/u105859802/public_html/amateur1, the Symfony public directory to serve is /home/u105859802/public_html/amateur1/web/

You should use

RewriteBase /amateur1/web/

But beware, it is not safe
You have to protect your symfony directories! (configuration is accessible)

Why don't you try moving your symfony files in your private area ?
You can rename the Symfony web directory to public_html

See how to do that in documentation cookbook

So, my recommendation structure looks like below :

  • /home/u105859802/
    • vendor
    • src
    • app
    • bin
    • public_html (web by default in symfony2) <- the only public directory
Touki
  • 7,465
  • 3
  • 41
  • 63
julien rollin
  • 1,607
  • 1
  • 12
  • 17
  • Do you mean to move my sf dir to */home/u105859802/amateur1/* being a sibling (brother) of */home/u105859802/public_html/* And putting into */public_html/* dir the contents of my */web/* directoy. Then *public_html/.htaccess* file should just redirect everything to app without *RewriteBase* or being just *RewriteBase /* right ? this way `RewriteRule ^(.*)$ app.php [QSA,L]`. – Jeflopo Feb 15 '13 at 14:09
  • I can't try it now, let me try it before accepting the answer. Thank you for this useful info ! – Jeflopo Feb 15 '13 at 14:18
0

In most of the shared hosting, you can't override Apache settings in that case may need to wright a redirection rule in .htaccess file

Options +FollowSymLinks +ExecCGI

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]

this is the rule I used in my project . You may need to provide full paths to your assets other ways they will not get loaded .

kiran Mohan
  • 68
  • 1
  • 3