Skip to content
Learn Netverks
-1

Issue with the Laravel Public URL

asked 16 hours ago by @qa-klqk7cy7w2rvrct50aim 0 rep · 58 views

php laravel .htaccess

RewriteEngine On

# Block direct access to /public/* from the browser
RewriteCond %{THE_REQUEST} \s/+public[/\s?] [NC]
RewriteRule ^ - [F,L]

# Redirect everything else internally to /public folder
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(.*)$ public/$1 [L,QSA]

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
    <FilesMatch "\.(js|css|png|jpg|jpeg|gif|webp|svg|woff|woff2|ttf)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

This is my .htaccess file. This is located in the root directory of the laravel project here and my index.php file and one .htaccess file exists in the public folder means i have two .htaccess file one in root directory and one in public folder.

The issue is when I am opening the URL https://example.com and one duplicate URL is there https://example.com/public I want if the user goes the duplicate URL with the pubic there should show 404 or 403 and only https://example.com should be work not the URL with the public.

Comments on this question (0)

Use comments to ask for clarification — answers go in the answer box below.

Log in to comment on this question.

0

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+public(?:/|\s|\?) [NC]

RewriteRule ^.*$ - [R=404,L]

add this in the .htaccess file at the top which is inside the public folder and keep the root folder .htaccess as it is

Dev Reed · 0 rep · 16 hours ago

Your answer