简体   繁体   中英

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.

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

help me with htaccess handling

You can ignore files using

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

You can use this as your .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

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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