Changing the root folder via .htaccess

后端 未结 4 1008
庸人自扰
庸人自扰 2020-12-01 16:41

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

相关标签:
4条回答
  • 2020-12-01 17:19

    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.

    0 讨论(0)
  • 2020-12-01 17:21

    This is how i always use it in my framework:

    Rewritecond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) /example.com/public/$1 [L,NC]  
    
    RewriteCond %{REQUEST_URI}  ^/$
    RewriteRule !^example.com/public/(.*) /example.com/public/$1 [L,NC]
    
    0 讨论(0)
  • 2020-12-01 17:27

    I use bluehost... this is what works for me: This is helpful when you are on shared hosting, and have multiple domain names.

    Your primary domain is set to public_html but your add-on domains are subfolders inside public_html

    This makes it so you don't have to have all your primary domain name files be mixed with add-on domain folders... each domain can be in their own folder...

    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^(www.)?PUTYOURDOMAINNAMEHERE.com$ 
    RewriteCond %{REQUEST_URI} !^/PUTYOURFOLDERHERE/ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /PUTYOURFOLDERHERE/$1  
    RewriteCond %{HTTP_HOST} ^(www.)?PUTYOURDOMAINNAMEHERE.com$ 
    RewriteRule ^(/)?$ PUTYOURFOLDERHERE/ [L]
    Options +SymLinksIfOwnerMatch
    
    0 讨论(0)
  • 2020-12-01 17:34

    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.

    0 讨论(0)
提交回复
热议问题