Bilal Khalid
Bilal Khalid

Reputation: 95

How to hide a specific file in Code igniter / PHP?

I have a web project and i have created an external photo library for my project.The photo library is outside the web root directory e.g My Codeigniter project is in C:\wamp\www\myprject\application\ but my photo library is under C:\wamp\www\myprject\Lib\

My .htaccess file (under my application folder ) successfully displays the library using the commands below:

.htaccess file

RewriteEngine on  
RewriteCond $1 !^(index\.php|images|Lib|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php?$1 [L]

But the problem is this .htaccess file is also displaying my error_log file along with all the images in the library directory. What changes i will need to make in this .htacess file to hide it?I just want to display (.jpg,gif,.bmp,.jpeg) files.Please help.Thanks

Upvotes: 0

Views: 1127

Answers (2)

Jirilmon
Jirilmon

Reputation: 1944

Do workarounds with 'FilesMatch' tag.

Add this after your RewriteCond and RewriteRule:

<FilesMatch "Lib\.(htaccess|htpasswd|ini|log|error_log|error|sh|inc|bak)$">
Order Allow,Deny
Deny from all
</FilesMatch>

Note: please add your error log file's extenstion in between the pipe ' | ' symbols. Also please remove extensions that you don't want.

More info: How to hide certain file type using apache .htaccess?

Upvotes: 1

swatkins
swatkins

Reputation: 13640

I'm not an .htaccess guru, but you should be able to change it to:

## NOT TESTED ##
RewriteEngine on  
RewriteCond $1 !^(index\.php|images|Lib\/*\.jpg|Lib\/*\.gif|Lib\/*\.bmp|Lib\/*\.jpeg|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php?$1 [L]

Lib\/*\.jpg is a regex for any jpg file under the Lib directory

Upvotes: 0

Related Questions