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:
- Visit
http://localhost/laravel/X/X
(where X is anything) - Get redirected to
http://localhost/laravel/public/index.php/X/X
(with the public/index.php hidden from the url to prevent duplicate urls) - Visit
http://example.com/X/X
(where X is anything) - Get redirected to
http://example.com/public/index.php/X/X
(with the public/index.php hidden from the url to prevent duplicate urls) - Prevent access to directories/files outside of public folder, and prevent access to directories in public folder, but not files.
- 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/