简体   繁体   English

保护文件夹内的特定文件

[英]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. 我使用.htaccess来保护我的管理区域,并使用redirect脚本将index.php文件包含在所有文件夹中,以便没人能在文件夹内列出我的文件。 eg Images, css etc 例如Images, css

If someone want to access http://www.mainDomain/scripts/ it will redirect to http://www.mainDomain/ 如果有人要访问http://www.mainDomain/scripts/ ,它将重定向到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) 但是,如果有人想访问http://www.mainDomain/scripts/style.css ,我将如何重定向(以防止我们的代码被复制)

CSS is client side language and you can not protect it. CSS是客户端语言,您无法保护它。 If you do not give access to your CSS files to remote browser it simply can not use them to render page. 如果您不将CSS文件的访问权限授予远程浏览器,则根本无法使用它们来呈现页面。

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. 返回网页时发送给客户端的任何内容(通常是html / css以及可能的JavaScript的组合)都将由客户端可见并且可编辑。 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. 假定您需要style.css作为页面(之一)上的样式表,则不能阻止用户查看它。 (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. 从技术上讲,可以阻止外部地址打开.css ,同时允许服务器端访问,但是当包含在html页面中时,也将阻止文件。

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; 您可以阻止某人对其进行热链接,但不能阻止他们查看您的CSS文件。 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. 您可以编写一个文件来检查请求中的IP地址。 If the ip is from the server; 如果ip来自服务器; allow it, otherwise disallow it? 允许它,否则不允许它? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM