doudianhuo1129 2013-12-05 19:29
浏览 8
已采纳

仅允许.htaccess从一个目录到另一个目录

I have mp3's in a directory called /mp3/ and I want to be able to access them only from another page.php in another directory /main/ on the site. No direct linking from outside.

All of the pages are written in php

I put this code in the .htaccess file inside the /mp3/ directory...

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

But none of those work. It does work however if I use the IP address of were I am.

allow from 1.2.3.4  # my internet connection (real one used in code)

But that means it would work for anyone and their IP address.

What am I missing here? Does this work only on certain servers? How do I make it use the server's IP address and not my IP address?

  • 写回答

5条回答 默认 最新

  • doudaochu1699 2013-12-05 23:51
    关注

    Look into "hotlink protection" added to your .htaccess file. You can set it up for just .mp3 file extension, and forbid access by any foreign site or directly from browsers. You might even be able to restrict access from within your own site, but I can't see that being terribly useful.

    Something like

    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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题