Translate "Remove public directory" in the Laravel project into Chinese as "Remove public directory"
P粉898049562
P粉898049562 2024-04-03 19:26:05
0
1
363

I'm making a Laravel project but I have a big problem, I can't remove the /public/ name from my URLs. I saw a solution to move some files from the public directory to laravel's root directory, but I also learned that this is an unsafe technique. So I need to solve this problem with .htaccess since I don't have access to apache.

I created a .htaccess in the root directory, but that just made it work without the public name in the URL, but the routes inside laravel still show the public name. please help. I tried using other htaccess rules to remove the full public, but internal routing for css, livewire, js, etc. files doesn't work because all of them have public urls.

<ifmodule mod_negotiation.c>
    Options -MultiViews
</ifmodule>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^ [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

P粉898049562
P粉898049562

reply all(1)
P粉738821035

I encountered the same problem and I had to move the path of the domain name settings from "public_html/" to "public_html/public". Then in your "public_html/public/.htaccess" file I have the following settings:

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

    RewriteEngine On

    # 处理授权头部
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # 将请求发送到前端控制器...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!