title: Redirect subfolder to root and hide it in the url
body: <p>I have managed to "rebase" the root from a directory in order to keep public files separated from configs, helpers, and controllers, thanks to <a href="https://stackoverflow.com/questions/35304201/how-to-redirect-to-a-subfolder-and-then-rewrite-subfolder-link-to-root-in-htacce">this answer</a> and <a href="https://stackoverflow.com/questions/35367895/how-to-redirect-to-a-subfolder-from-root-rewrite-subfolder-link-to-look-like-ro">this answer</a>.</p>
  
  <p>However I realized that if a user type <code>http://domain.com/public</code> it will not redirect to <code>http://domain.com</code> this is harmful for SEO because robots will treat them as two urls thus duplicate.</p>
  
  <p>I need to 301 redirect <code>/public</code> to root but as long as I am trying. It doesn't work.</p>
  
  <p>My htaccess looks like the following:</p>
  
  <pre><code># Options
  Options +FollowSymLinks +MultiViews -Indexes
  DirectorySlash off
  
  # Enable Rewrite Engine
  RewriteEngine on
  RewriteBase /
  
  # Exceptions
  RewriteCond %{REQUEST_URI} ^/(images|javascripts|stylesheets)/ [NC]
  RewriteRule ^ - [L]
  
  # www to non-www
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteCond %{HTTPS}s ^on(s)|
  RewriteRule ^ http%2://%1%{REQUEST_URI} [L,R=301]
  
  # Make /public like it was root
  RewriteCond %{THE_REQUEST} /public/([^\s]+) [NC]
  RewriteRule ^ /%1 [NC,L,R]
  RewriteCond %{REQUEST_URI} !^/public
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ /public/$1 [NC,L,QSA]
  
  # Error pages
  ErrorDocument 403 /errors/403.php
  ErrorDocument 404 /errors/404.php
  ErrorDocument 500 /errors/500.php
  
  &lt;files .htaccess=""&gt;
    order allow,deny
    deny from all
  &lt;/files&gt;
  </code></pre>
  
  <p>In this way it will redirect to <code>http://domain.com//</code></p>
  
  <p>How can I fix this issue?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My website directory structure is:</p>
  
  <pre><code>·
  |__data
  |__controllers
  |__helpers
  |__partials
  |__layouts
  |__images
  |__javascripts
  |__stylesheets
  |__public
     |__index.php
     |__subfolder
        |__index.php
  </code></pre>
  
  <p>In root there won't be any index.php pages. So I need to make the <code>/public</code> dir as it was my root, in order to keep configs and other directories that users don't have to see separate.</p>