Htaccess remove /public/ or /server-folders from url

Hello guys,

I do not have access to this server to change root path and i have to do this via htaccess. However i failed miserably so far. Here is what i'm trying to do:

  • example.com/public/ should redirect to example.com
  • example.com/public/page-title should redirect to example.com/page-title
  • example.com/server-folder-1/server-folder-2/ should redirect to example.com
  • example.com/server-folder-1/server-folder-2/page-title should redirect to example.com/page-title
  • example.com/server-folder-1/server-folder-2/public/ should redirect to example.com
  • example.com/server-folder-1/server-folder-2/public/page-title should redirect to example.com/page-title

I tried with different redirects both in root and public htaccess but cant seem to get it working.. I have a strange feeling that something is messed up with the server.

edited Apr '16

Put your .htaccess to root folder

Require all granted

<IfModule mod_rewrite.c>
    RewriteBase       /
    RewriteEngine   On
    RewriteCond     %{REQUEST_FILENAME} !-f
    RewriteRule       ^(.*)$    public/index.php?_url=$1    [QSA,L]
</IfModule>

also dont forget to secure other folders which should not be accessed from the internet with .htaccess

Require all denied

Hey @David, I have not forgot about this, just really busy recently and I can't spend much time testing on this. Will replay when I do some tests.

Thanks! :)