3

I am attempting to create htaccess files that can be used on development and production server. The development server's folder structure is like this:

Server Root (www)
 -laravel
  -public
   -index.php
    -controller/method... etc

The production server does not have a document root that is not publicly accessible. I am deploying this on appfog, and it requires .htaccess to do this. This is mentioned on Appfog's documentation: https://docs.appfog.com/languages/php#custom

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

The production server's folder structure will be like this (it simply removes the laravel folder):

Server Root (www)
 -public
  -index.php
   -controller/method... etc

I would like to achieve this without the use of apache httpd, only using htaccess because the development environment will change constantly.

I would like to be able to do this:

  1. Visit http://localhost/laravel/X/X (where X is anything)
  2. Get redirected to http://localhost/laravel/public/index.php/X/X (with the public/index.php hidden from the url to prevent duplicate urls)
  3. Visit http://example.com/X/X (where X is anything)
  4. Get redirected to http://example.com/public/index.php/X/X (with the public/index.php hidden from the url to prevent duplicate urls)
  5. Prevent access to directories/files outside of public folder, and prevent access to directories in public folder, but not files.
  6. All without having to change configurations on between production and development

The question, how do I do this and how many .htaccess files do I need?

My progress so far has been going through the laravel documentation and this forum post, but no matter what I do, I keep either getting 404s or 500 server errors when I just go to http://localhost/laravel/

CMCDragonkai
  • 6,222
  • 12
  • 56
  • 98

2 Answers2

0

Take a look at a possible option here.

Mxyk
  • 10,678
  • 16
  • 57
  • 76
mogetutu
  • 508
  • 3
  • 11
0

You would be placing that in your application's root.

- application/
- public/
  - .htaccess (already provided by laravel)
- index.php/
- .htaccess (the one specified by appfog)

Everything should work fine.

Jürgen Paul
  • 14,299
  • 26
  • 93
  • 133