2

I'm trying to get a Laravel 4 app installed in a subfolder of the web root directory for one of my users. I know there are major security concerns having the entire framework accessible via the web. I plan to address those separately after I understand how to get this working.

I've tried every combination of Apache Aliases, and Rewrite rules I can think of, but nothing seems to work. Here's my directory structure:

/home/username/public_html
    .htaccess
    my_laravel_app/
        app/
        bootstrap/
        public/
            .htaccess
            index.php
            robots.txt
            ...etc (standard Laravel 4 public folder contents)
        vendor/
        ...etc (standard Laravel 4 files and folders)

The first .htaccess file, the one listed directly under the users public_html directory, contains the following:

AuthType Basic
AuthName Private
Authuserfile /path/to/.htpasswd
Require valid-user

The second .htaccess is a standard Laravel 4 .htaccess file. It contains the following:

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

I would like to essentially treat this my_laravel_app/public directory as a webroot, so that the Laravel app functions the same way it would if for a normal Laravel installation directly on a domain.

I believe I just need to edit the first .htaccess file to contain rewrite rules that send any request to /my_laravel_app to my_laravel_app/public, but I can't seem to get this working. Can anyone help?

flyingL123
  • 7,686
  • 11
  • 66
  • 135
  • The finaly rewriterule if I am not mistaken should be `/my_laravel_app/public/index.php`. Oh and you can also modify the Rewrite Condition. I had it done on another server let me look it up – MiltoxBeyond Jun 25 '15 at 16:36
  • Possible duplicate of _[How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder?](http://stackoverflow.com/questions/16683046/how-to-install-laravel-4-to-a-web-host-subfolder-without-publicly-exposing-app)_ And, you might find this answer helpful: http://stackoverflow.com/a/27350400/1947276 – little pootis Jun 25 '15 at 16:41

1 Answers1

0

This may be different depending on your setup, but the base config is:

RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/my_laravel_app/public/%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/my_laravel_app/public/%{REQUEST_URI} -f
RewriteRule . public/%{REQUEST_URI} [L]

RewriteRule . public/index.php [L]

And put inside your my_laravel_app as an .htaccess to limit the complexity of the conditions. You get the idea hopefully.

MiltoxBeyond
  • 2,683
  • 1
  • 13
  • 12
  • Thanks. Can you please clarify what you mean by "And put inside your my_laravel_app as an .htaccess to limit the complexity of the conditions". Are you saying that the code you're showing should be placed in an `.htaccess` file under `my_laravel_app` directory? – flyingL123 Jun 25 '15 at 16:45
  • It would be ideal inside the my_laravel_app. Not necessary, but if you don't, then the conditions have to be modified to include a check for anything requesting a document in the laravel folder. – MiltoxBeyond Jun 25 '15 at 18:18