Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: RewriteCond question |
|
| Author |
|
edwardsmarkf
Joined: 20 Feb 2013 Posts: 27 Location: cottonwood, az
|
Posted: Fri 20 Mar '26 5:20 Post subject: RewriteCond question |
|
|
hi all -
i have a situation where i have 10's of thousands of media files. Unfortunately, the sub-directory names are email addresses, and i need to BLOCK all access if a request does NOT contain the media name, like "file.mp3"
the directory is structured like this:
| Quote: | /mainDir/email-1@google.com/email-2@google.com/file.mp3
/mainDir/email-1@google.com/email-3@google.com/file1.mp3
/mainDir/email-1@google.com/email-4@google.com/file2.mp3
/mainDir/email-5@google.com/email-6@google.com/file3.mp3
/mainDir/email-5@google.com/email-7@google.com/file4.mp3
/mainDir/email-5@google.com/email-8@google.com/file5.mp3
/mainDirA/mainDirB/e-9@google.com/e-10.google.com/xx.mp3
/mainDirA/mainDirB/e-11@google.com/e-12.google.com/yy.mp3 |
so if i saw a request that looks like any of the following (notice missing the mp3 file name):
these need to be blocked. currently i have a blank 'index.html' file in every directory, but this seems clumsy at best.
i am thinking a mod_rewrite that looks something like this:
| Code: | RewriteCond /mainDir/ [OR]
RewriteCond /mainDirA/mainDirB/
RewriteRule !"\.mp3" "-" [F] |
is this adequate? or should i use something like these?
| Code: |
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !-f |
its been a LONG time since i have used any mod_rewrite stuff and have forgotten most of it, sorry to say. |
|
| Back to top |
|
Stray78

Joined: 15 Apr 2024 Posts: 59 Location: USA
|
Posted: Fri 20 Mar '26 22:49 Post subject: |
|
|
Put this in your .htaccess:
| Code: | RewriteEngine On
# Allow ONLY .mp3 files
RewriteCond %{REQUEST_URI} !\.mp3$ [NC]
RewriteRule ^ - [F,L]
# Disable directory browsing
Options -Indexes |
|
|
| Back to top |
|
|
|
|
|
|