Laravel 7.x - How to remove 'public' from URL?

别来无恙 提交于 2021-02-10 06:23:07

问题


Stuck with this for a long time. I found similar questions but none of the answers are working for me! .htaccess in root folder looks like this:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule ^(.*)$ /public/$1 [L,QSA]

回答1:


Create a file named as '.htaccess' in root and add the below code. That's it

RewriteEngine On

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

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

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



回答2:


The example here is in the /public directory. You will also need to configure you're server correctly and have it look only at the /public directory instead of root. You shouldn't need an .htaccess file in the root.

You will need a httpd-vhosts.conf with something like the following:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName yourapp.com
    ServiceAlias www.yourapp.com
    DocumentRoot /var/www/yourapp/public
</VirtualHost>

Notice this line:

DocumentRoot /var/www/yourapp/public

You can read more about Laravel webserver configuration here.



来源:https://stackoverflow.com/questions/61806001/laravel-7-x-how-to-remove-public-from-url

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