Laravel public folder returns 404 error (.htaccess)
P粉238433862
P粉238433862 2023-07-28 18:04:13
0
1
520
<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>
P粉238433862
P粉238433862

reply all(1)
P粉604669414

Try using the following:

SetEnv DEFAULT_LANG en

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -Indexes

    RewriteEngine On

    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 ^(.*)$ ?language=%{ENV:LANGUAGE} [QSA]

    RewriteCond %{REQUEST_URI} !^/public
    RewriteRule ^(.*)$ /public/?language=%{ENV:LANGUAGE} [L,QSA]

</IfModule>

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template