问题
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