I've got a shared hosting account associated with a domain name and the root folder (correct me if that's the wrong term) is set to /
so that all files on the server are public / accessible through the browser.
Can I use .htaccess or something to change the root folder to something like /example.com/public/
?
htaccess file is a powerful website file that controls high-level configuration of your website. On servers that run Apache (a web server software), the . htaccess file allows you to make changes to your website's configuration without having to edit server configuration files.
The . htaccess is not required for having a general website. That file simply allows you to make changes in the way your website behaves for example banning people from accessing your site or redirecting an old dead link to a new page.
If I'm understanding correctly, the following should work
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]
This will redirect all requests that do not begin with /public/
to URL that does.
Hope that helps.
The DocumentRoot directive can't be set in a .htaccess file, only in the server config. As you most likely don't have the privileges to modify the server settings your only solution is to use some rewrite magic as clmarquart already mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With