我在名为/mp3/
的目录中有mp3,我希望只能从网站上另一个目录page.php
中的另一个/main/
访问它们。
没有外界的直接联系。
所有页面均以php
我将此代码放在.htaccess
目录中的/mp3/
文件中......
Order deny,allow
deny from all
allow from 127.0.0.1
allow from localhost
allow from mydomain.com
allow from 123.45.678.90 # that's myserver's IP address (real one used in code)
Satisfy Any
但这些都没有奏效。 如果我使用的是我的IP地址,它确实有用。
allow from 1.2.3.4 # my internet connection (real one used in code)
但这意味着它适用于任何人及其IP地址。
我在这里缺少什么?这仅适用于某些服务器吗? 如何使用服务器的IP地址而不是我的IP地址?
答案 0 :(得分:1)
查看添加到.htaccess文件的“hotlink protection”。您可以将其设置为.mp3文件扩展名,并禁止任何外国站点或直接从浏览器访问。您甚至可以限制自己网站内的访问权限,但我看不出它非常有用。
像
这样的东西RewriteEngine on
Options +FollowSymlinks
# hotlink protection and allowed list
# don't forget to add https: to allow accesss for any with SSL
## uncomment following line to PERMIT direct browser access of mp3 files
#RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com(/)?.*$ [NC]
RewriteRule .*\.mp3$ - [F,NC]
答案 1 :(得分:0)
将要保护的文件放在公用文件夹之外。这样,只能通过脚本访问它们。
-root
--mp3s
--public_html
---main
----index.php
----page.php
答案 2 :(得分:0)
您是试图限制“推荐”而不是直接访问?
拒绝IP限制所有访问权限,无论是page.php引用还是在浏览器的URL位置栏中输入。如果您尝试限制推荐,可以尝试使用以下内容:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain.com/ [NC]
RewriteRule ^mp3/ - [L,F]
但请注意,引用者可能会被欺骗。
答案 3 :(得分:0)
在.htaccess
<Files ~ ".mp3$">
Order allow,deny
Deny from all
</Files>
这不允许从您的网络服务器直接访问.mp3
的任何文件。
答案 4 :(得分:0)
将此代码放在mp3/.htaccess
文件中:
RewriteEngine on
RewriteBase /mp3/
RewriteCond %{HTTP_REFERER} !^https?://(localhost|(www\.)?mydomain\.com)/ [NC]
RewriteRule ^ - [F]