Ignore the empty folder (403) and pass the URI to the Laravel controller with .htaccess

让人想犯罪 __ 提交于 2021-01-29 04:52:55

问题


I have a project with Laravel and inside the public folder (httpdocs) I have a folder /en/news, all works fine with the route /en/news but when I try to go to the /en I have a 403 error because it is a empty folder, the real problem there is that /en is a route in my Laravel project with the homepage of the web, so first executes de .htaccess and throw the 403. Is there any way to ignore this error for this specific folder/route (/en) or something like that?

My .htaccess is the tipical Laravel .htaccess

<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]

回答1:


The solution:

Add before the # Send Requests To Front Controller... the next rewrite:

RewriteRule ^en/$ index.php [L]

This send the request to the index.php ignoring the checks for this specific route.



来源:https://stackoverflow.com/questions/63167421/ignore-the-empty-folder-403-and-pass-the-uri-to-the-laravel-controller-with-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!