只允许.hta从一个目录访问另一个目录


Allow .htaccess only from one directory to another

我在一个名为/mp3/的目录中有mp3,我希望只能从网站上另一个目录/main/中的另一个page.php访问它们。没有来自外部的直接链接。

所有页面都用php 书写

我把这个代码放在/mp3/目录下的.htaccess文件中。。。

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地址?

查看添加到.htaccess文件中的"热链接保护"。你可以将其设置为.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]

将要保护的文件放在公用文件夹之外。这样,它们只能通过脚本访问。

-root
--mp3s
--public_html
---main
----index.php
----page.php

您试图限制"推荐"而不是直接访问?

拒绝IP限制所有访问权限,无论是您的page.php引用的还是在浏览器的URL位置栏中键入的。如果你试图限制推荐,你可以尝试使用以下内容:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https?://(www'.)?yourdomain.com/ [NC]
RewriteRule ^mp3/ - [L,F]

但请注意,裁判可能会被欺骗。

.htaccess 中这样的东西怎么样

<Files ~ ".mp3$">
    Order allow,deny
    Deny from all
</Files>

这将不允许从您的web服务器直接访问任何带有.mp3的文件。

将此代码放在mp3/.htaccess文件中:

RewriteEngine on
RewriteBase /mp3/
RewriteCond %{HTTP_REFERER} !^https?://(localhost|(www'.)?mydomain'.com)/ [NC]
RewriteRule ^ - [F]