-1

My symfony project is in public_html/web/app.php What I want is to redirect all requests on my site example.com to open app.php in that path without displaying the full path in address bar. i.e. though file path will be example.com/web/app.php all user should see is example.com in address bar.

Rzl
  • 1
  • 3
  • as u mentioned in your tag htaccess also perform this task – user1844933 Jul 22 '15 at 08:57
  • A default symfony project already includes the required htacces file. You only need to setup your hosting to use `/web` as the web root directory. – Yoshi Jul 22 '15 at 08:59
  • i tried htaccess. surfed through net and did what others have done.. what worked for them is not working for me – Rzl Jul 22 '15 at 09:01
  • @Yoshi seems i cant do that as well. I tried add on domains , redirects everything.. – Rzl Jul 22 '15 at 09:02
  • What I'm saying is that you should probably not try to solve this with your symfony project, but rather with the tools your hosting environment gives you. Try looking for a configuration option to define the document/web-root folder. – Yoshi Jul 22 '15 at 09:02
  • Nope. i bought hosting from local merchant in my country.. and got credentials. – Rzl Jul 22 '15 at 09:07
  • I see, well, then as I said, try looking for a way to configure your exposed web-root. Though, it could of course be that, depending on the package you bought, you are not allowed to change this. If so, you'll probably be better of, looking for another service provider. – Yoshi Jul 22 '15 at 09:09

2 Answers2

0

Try this in your public_html/.htaccess

RewriteEngine on
RewriteRule ^.*$ /web/app.php [NC,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • already tried a lot of things.. nothing works. this does not work as well. it still points to public_html – Rzl Jul 22 '15 at 08:59
  • i have created index.html in public_html folder with some content.. after i type the url. i try open index.html the file which is located in public_html is opening up – Rzl Jul 22 '15 at 09:03
  • Can you post the contents of your htaccess file? – Amit Verma Jul 22 '15 at 09:09
  • 'code' RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.hamrosahitya\.com$ RewriteRule ^(.*)$ http://www.hamrosahitya.com/$1 [R=301,L] RewriteRule ^$ /app.php RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !\..+$ RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://www.hamrosahitya.com/$1/ [L,R=301] 'code' RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/web/ RewriteRule ^(.*)$ /web/$1 – Rzl Jul 22 '15 at 09:17
  • Do you want to redirect all incomming requests (including existing files and dirs) to /web/app.php ? – Amit Verma Jul 22 '15 at 09:22
0

As @Yoshi pointed out in the comments, you need to set the DocumentRoot of your site to .../public_html/web, and not to ../public_html.

If that is correct, you should be able to surf your app as:

example.com/app.php

After that, you can use the mentioned .htaccess rules to redirect and remove the "app.php" part.

That is the standard Symfony configuration. If you want to do something unusual and put Symfony in a subfolder of an existing site, that is a different question that has already been answered: How can I deploy Symfony in a subdirectory?

Community
  • 1
  • 1
Francesco Abeni
  • 4,190
  • 1
  • 19
  • 30