navid
navid

Reputation: 823

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.

and my site directory in my computer(wamp):

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]

Upvotes: 1

Views: 8242

Answers (3)

Jon Lin
Jon Lin

Reputation: 143866

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.

Upvotes: 0

Jesús Quintana
Jesús Quintana

Reputation: 1813

  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.

Upvotes: 1

tholu
tholu

Reputation: 1142

Put everything in

/home/mysite

and configure your virtual host to use

/home/mysite/public/

as DocumentRoot. Put the .htaccess in

/home/mysite/public/

Upvotes: 0

Related Questions