Laravel PHP Framework: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
== Making Subdirectories Accessible without a Public folder ==
== Making Subdirectories Accessible without a Public folder ==


Technically there is some risk to this, but I find it useful for development and preventing the need to create apache config files for every Laravel project.
Technically there is some risk to this since it could potentially expose configuration files in the root directory. I negate this somewhat by adding a DENY rule to .env files. I still wouldn't recommend it for a production site, but I find it useful for development and preventing the need to create apache config files for every Laravel project.


- Create a Laravel project
- Create a Laravel project

Revision as of 21:57, 11 December 2016

Making Subdirectories Accessible without a Public folder

Technically there is some risk to this since it could potentially expose configuration files in the root directory. I negate this somewhat by adding a DENY rule to .env files. I still wouldn't recommend it for a production site, but I find it useful for development and preventing the need to create apache config files for every Laravel project.

- Create a Laravel project

laravel create newproject

- Rename the 'server.php' file to 'index.php' in the root directory

- Add a .htaccess file to the root directory:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteRule ^(.*)/$ /hello/index.php/$1 [L]

</IfModule>

<Files .env>
    Order Allow,Deny
    Deny from all
</Files>

Note: Customize the RewriteRule line to match your subdirectory.