Search code examples
laravelapache.htaccess

Laravel keep redirects under public folder


I have a Laravel project hosted at https://subdomain.myserverdomain.com, and I'm encountering an issue with URL redirection. The project is set up under the "subdomain" folder, and when I navigate to https://subdomain.myserverdomain.com/panel/ in the browser, it redirects to https://subdomain.myserverdomain.com/public/panel/. Correct URL https://subdomain.myserverdomain.com/panel works just fine but sometimes project users type the last slash and it will cause asset problems. They are typing the URL because there is no anchor from front end of this website.

I've tried modifying the .htaccess file at root, but the issue persists. Additionally, I've checked and adjusted my Apache configuration, but haven't found a solution.

Here is my .htaccess file at project root:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/public
 RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

How can I correct this?

I would like all routes like '/panel/ redirects to '/panel' url, not '/public/panel' url.


Solution

  • I found the solution for Plesk users. There is a setting called Document root in Domain > Hosting Settings in Plesk. If you edit and add your /public folder in this setting, assets and all the other things will be loaded correctly.

    I didnt know you can do this for a subdomain, but apparently you can. Thanks for your help.

    Hosting Settings