简体   繁体   中英

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. eg 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)

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.

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.

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.

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? :)

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