.htaccessshared-hosting

How to remove folder from URL with .htaccess


Before you "kindly" mark this as a duplicate to another question, I must say I tried how they did it and it doesn't work.

But at first, I also have to ask, if the changes are visible on local host, too?

I have a website in laravel on shared hosting where the URL for homepage must be:

website.local/public/

...so it can find it. It is in URLs for other pages as well.

And I want to remove the /public/ part, of course.

My .htaccess looks like this at this moment:

RewriteEngine On
RewriteRule ^$ /public [L]

What should I do to succeed?

Thanks.


Solution

  • You probably want something along those lines:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/public
    RewriteRule ^ /public%{REQUEST_URI} [L]
    

    Your prior attempt only rewrote the empty URL (https://example.com/). And it implemented an endless rewriting loop.