简体   繁体   English

允许仅使用htaccess访问一个php文件

[英]allow access to only one php file with htaccess

I have few media files in a folder and a php file on same folder, I want to deny access for any media file accessing directly, but I want to access those media files only via the php file there. 我在一个文件夹中没有几个媒体文件,而在同一文件夹中有一个php文件,我想拒绝任何直接访问的媒体文件的访问,但是我只想通过那里的php文件访问那些媒体文件。

lets say my_folder containing index.php, movie1.mp4, movie2.mp4 etc, I want to deny movie1.mp4 and movie2.mp4 straightly, but I need to allow by index.php 可以说my_folder包含index.php,movie1.mp4,movie2.mp4等,我想直接拒绝movie1.mp4和movie2.mp4,但我需要index.php允许

help me with htaccess handling 帮助我进行htaccess处理

You can ignore files using 您可以使用忽略文件

RewriteRule ^/?/file\.mp4$ - [F,L]

You can use this as your .htaccess . 您可以将其用作.htaccess All the request will be redirected to index.php in that directory & also all the request made to mp4 files will be redirected to index.php 所有请求将被重定向到该目录中的index.php,对mp4文件的所有请求也将重定向到index.php

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?/file\.mp4$ - [F,L]
RewriteRule . /index.php [L]
</IfModule>

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

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