Laravel public folder access

rpmg.infinityfreeapp.com

Greetings!
I just uploaded my laravel project and it is working, but my url always go to the ‘/public’ url.

I was wondering if i did something wrong with my .htaccess files

.htaccess in htdoc folder

# To prevent access to .env and other files
<Files .*>

# Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
</Files>

<IfModule mod_alias.c>
RedirectMatch 301 ^/$ http://rpmg.infinityfreeapp.com/public
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect all requests to the Laravel public directory
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

.htaccess in public folder

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

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

Yes, that’s what this particular piece of .htaccess code is doing:

The rules just below that will also make Laravel work without any redirects. So you can safely remove these three lines and everything will work.

4 Likes

oh, okay will do right away…

will it also affect if i have let say trying to upload some photos using the public folder?

If you remove that redirect rule, everything should work as expected. Both PHP pages and static files.

Technically, it basically identical to our recommended .htaccess code: .htaccess for Laravel

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.