Arif
Arif

Reputation: 1211

Protect specific files inside folder

I used .htaccess to protect my admin area and include index.php file in all folders with redirect script so that no one can list my files inside folder. e.g Images, css etc

If someone want to access http://www.mainDomain/scripts/ it will redirect to http://www.mainDomain/

But If someone want to access http://www.mainDomain/scripts/style.css how i will redirect(to protect our code from being copied)

Upvotes: 0

Views: 89

Answers (4)

Cerbrus
Cerbrus

Reputation: 72927

Whatever you send to the client when returning a webpage (Usually a combination of html / css and possibly JavaScript) Will be visible and edit-able by the client. You can't protect the transmitted data to prevent people from copying / editying it.

Assuming you need your style.css as a stylesheet on (one of) your pages, you can't block users from viewing it. (That would defeat the purpose of having the stylesheet, since you won't be using it then.)

Technically, it is possible to block external addresses from opening the .css, while allowing server-side access, but that would also block the file when included in a html page.

Not really the answer you're looking for, I'd wager, but sometimes, you just run into limitations of the software you're working with.

Upvotes: 2

Infinity
Infinity

Reputation: 3875

You can stop someone from hotlinking it but you can't stop them from viewing your css file; well technically you can but that will also disabled you from using it as well.

Upvotes: 2

loler
loler

Reputation: 2587

CSS is client side language and you can not protect it. If you do not give access to your CSS files to remote browser it simply can not use them to render page.

Upvotes: 3

Youri
Youri

Reputation: 505

You can write a file that checks the ip address from the request. If the ip is from the server; allow it, otherwise disallow it? :)

Upvotes: -2

Related Questions