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 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败