aleksov's avatar

Cant point /public folder with .htaccess laravel 5.3

I have folder /var/www/html/project/himp and there is my laravel installation. In /var/www/html/project is my landing page index.html and some css files.

Inside /himp folder I have .htaccess:


    <IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

also in /himp/public folder I have also .htaccess:


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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

Now when I go to the domain.com/himp/public I get Laravel installation and startup screen but when I go to the domain.com/himp I get just folder views, so there is no redirection to public folder ...

Why? What can be a problem here? Please help.

0 likes
18 replies
aleksov's avatar

I try also this:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/himp/public

RewriteRule ^(.*)$ public/$1 [L]

dont work ... really dont know what is a problem here...

jlrdw's avatar

Forget all this stuff

 RewriteEngine On

RewriteCond %{REQUEST_URI} !^/himp/public

RewriteRule ^(.*)$ public/$1 [L]

dont work ... really dont know what is a problem here...

Follow the instructions in the link I gave. If done correctly you shouldn't have to mess with htaccess.

aleksov's avatar

I dont undestand what I need to do to there really

aleksov's avatar

I just dont undestand this part:

Then for the final steps modify your “blog/index.php” file and adjust the following two paths.

// blog/index.php change to point to /var/www/laravel/

require DIR.'/../bootstrap/autoload.php'; $app = require_once DIR.'/../bootstrap/app.php'; This will keep everything outside your web root, make your install more secure, and prevent unauthorized access to import items.

...

I move into /laravel3 all files except public folder ... so in /laravel3/himp/public there is a files and there is index.php ... but what to change ... where?

jlrdw's avatar

When installed correctly, you resolve the paths to point to the correct folders. That why the /../

aleksov's avatar

I follow and I move all folders and files into /laravel3 folder and public is inside /himp folder ... dotn work. thanks for help.

jlrdw's avatar

Once setup correctly, did you try a dump autoload? @Snapey if there, maybe you can explain better than I can on proper setup / install.

SaeedPrez's avatar

My general feeling is people should stop installing Laravel in a sub folder, a wonderful framework like this deserves more respect.

I just dont undestand this part:

@aleksov that part is pretty simple, if you've followed the instructions, it asks you to edit the index.php file and make sure the 2 paths it includes point to where you put the rest of your application. Explicitly the bootstrap/autoload.php and bootstrap/app.php files

jlrdw's avatar

@SaeedPrez I guess I should have used "put" instead of "resolve", I have just always used resolve. Thanks

SaeedPrez's avatar

@jlrdw It's been 12 hours since my last cup of coffee, let me try again..

@aleksov

These two lines already exist in the index.php file..

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';

What you need to do is change paths so they can point to where you have bootstrap/autoload.ph and bootstrap/app.php relative to your index.php (the one you're editing)..

Imagine if I have this folder setup..

example_com
    - www // this is document root, points to http://example.com/
        - blog // where I put my index.php, points to http://example.com/blog/
    - laravel
        - app
        - bootstrap
        - config
        - etc..

So if I have the index.php file in the www folder and the rest of my application in the laravel folder, then I would need to change those two paths in the index.php to match the new folder structure..

So it should look something like this..

require __DIR__.'/../../laravel/bootstrap/autoload.php';

$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
jlrdw's avatar

I wonder if OP read the article in the link, Eric L. Barnes said to adjust those lines as needed, oh well.

jlrdw's avatar

@aleksov if you or at a point in development where are you are using any framework you should be also at a point where resolving a path is second nature, but it can be tricky to get it right you just have to try a couple times various ../ combinations.

allgood's avatar

Make sure you have two .htaccess file. one from the laravel project(inside public folder) and one in your folder usually inside public_html

Please or to participate in this conversation.