Laravel public folder returns 404 error (.htaccess)
P粉238433862
2023-07-28 18:04:13
<p>I have a .htaccess file. Through this file I can detect the language by subdomain. There is no problem in this regard. However, when I redirect the incoming request to a file under the public folder, I get a 404 error and the language doesn't work properly. </p>
<pre class="brush:php;toolbar:false;">SetEnv DEFAULT_LANG en
<IfModule mod_rewrite.c>
Options FollowSymLinks -Indexes
RewriteEngineOn
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTP_HOST} ^([a-z]{2}).([a-z0-9-] .[a-z] )$ [NC]
RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
RewriteCond %{ENV:LANGUAGE} ^$
RewriteRule (.*) - [QSA,E=LANGUAGE:en]
RewriteCond %{QUERY_STRING} !language=
RewriteRule ^(.*)$ $1?language=%{ENV:LANGUAGE} [QSA]
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule></pre>
<p><br /></p>
Try using the following:
Using the above, language detection should work properly even when redirecting to files under the public folder. The %{ENV:LANGUAGE} variable will remain unchanged throughout the rewrite, so the correct language parameters should be passed to the file in the public folder.