Forum Home
PC World Chat
 
Thread ID: 121604 2011-11-02 10:45:00 Hiding a file on a webserver bot (15449) PC World Chat
Post ID Timestamp Content User
1241474 2011-11-02 10:45:00 I want a way to hide a certain file from the public, but make it only visible to my PHP page. How would I do this? The file in question is an XML document located in a folder named public_html

I googled 'protecting file with .htaccess' and all I got were results detailing me on how to password protect a file which is what I do not want. Setting the file permissions (CHMOD) makes no difference at all.

I have also heard of putting 'deny from all' in my .htaccess file but then the file wouldn't be visible to the PHP document.
bot (15449)
1241475 2011-11-02 11:24:00 OK, I tried putting the deny from all bit in the .htaccess file in, and my PHP page seems to find it... bot (15449)
1241476 2011-11-02 11:31:00 'deny from all' in the .htaccess file will not prevent your PHP script from accessing it. Your PHP script does not (or should not) access it via the URL, but just accesses the file directly.

The other good option is to place the file outside the webroot (ie, outside the directory where the web pages live).
george12 (7)
1241477 2011-11-02 18:02:00 I'm with george12, move it outside the webroot directory :) Chilling_Silence (9)
1241478 2011-11-03 07:07:00 Thanks :)

Another thing I want (and I will try and explain it as clearly as possible) is this:

Instead of mywebsite.com I want it to be like mywebsite.com dropping the php extension. I understand this can be achieved by editing the .htaccess file. Again, I would Google it but I do not know what to put in!
bot (15449)
1241479 2011-11-03 07:32:00 Again, I would Google it but I do not know what to put in!

Friendly URLs?
pcuser42 (130)
1241480 2011-11-03 11:29:00 Again, I would Google it but I do not know what to put in!Search for documentation on Apache's mod_rewrite - that will explain exactly what is needed. Erayd (23)
1