0

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

3
  • You'll need to use a RewriteCond to check against the REQUEST_URI, if that starts with /public/ you'll either rewrite to the root, or give a 403 Forbidden response. Commented Aug 27 at 6:08
  • 2
    You should not put files that are not meant to be public under public_html . The public_html folder should contain only the public folder contents . Have a look at stackoverflow.com/a/76897426/487813 as well Commented Aug 27 at 6:08
  • I would put laravel in /somefolder and make /public_html a symlink to /somefolder/public Commented Sep 2 at 0:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.