I have a PHP project deployed on shared hosting, and my files are structured like this:
/public_html/
.htaccess
/public/
index.php
...
I want the site to be accessible from:
https://test.com
but not directly from:
https://test.com/public
Currently, my .htaccess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
This works for routing, but if someone visits https://test.com/public, the folder is still accessible.
How can I modify my .htaccess so that /public is not accessible directly, but the site still loads correctly from the root domain?
Please help
/public/you'll either rewrite to the root, or give a 403 Forbidden response.public_html. Thepublic_htmlfolder should contain only thepublicfolder contents . Have a look at stackoverflow.com/a/76897426/487813 as well