Home  >  Q&A  >  body text

Translate "Remove public directory" in the Laravel project into Chinese as "Remove public directory"

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粉898049562P粉898049562179 days ago370

reply all(1)I'll reply

  • P粉738821035

    P粉7388210352024-04-04 09:54:16

    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>

    reply
    0
  • Cancelreply