简体   繁体   中英

access files outside public_html folder

I want to make some folder out of root directory ( public_html ). I have shared server linux with follow directory.

  • /home/ mysite
    • access-log
    • etc
    • mail
    • public_ftp
    • public_html
    • tmp
    • www

and my site directory in my computer( wamp ):

  • app
    • model
    • controller
    • view
  • config
  • public
    • images
    • css
    • js
    • index.php
  • htaccess

I want public folder to be placed into public_html folder in server. 1)how can I include my code using relative paths?

and I have htaccess file that points all requests to that public/index.php in my computer.

2)Where should I put my htaccess in my Shared server linux ?

my htaccess file:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
  1. You need place all public file in public_html.
  2. Move .htaccess to public html (that example not redirect to public/html only redirect to index.php and is fine)
  3. if have absoulute path example "../public" change to "../public_html", if is relative path is fine
  4. Move all other not public code in root folder.

You aplication must be running in this time.

Put everything in

/home/mysite

and configure your virtual host to use

/home/mysite/public/

as DocumentRoot. Put the .htaccess in

/home/mysite/public/

You can't traverse out of the document root using relative paths or rewriting in the htaccess file. You can include files from your php script ( index.php ). So what you can do is allow a request for something outside of public_html to be routed to index.php , then in php, load the file outside of public_html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM