| Author |
|
edwardsmarkf
Joined: 20 Feb 2013 Posts: 29 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: 61 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 |
|
edwardsmarkf
Joined: 20 Feb 2013 Posts: 29 Location: cottonwood, az
|
Posted: Sat 21 Mar '26 3:51 Post subject: |
|
|
thank you!
i just looked & saw some other formats. following your excellent suggestion, i am guessing i can do something like this as well?
| Code: | RewriteEngine On
# Allow ONLY .mp3 files, OR
RewriteCond %{REQUEST_URI} !\.(wav|mp3|opus)$ [NC]
RewriteRule ^ - [F,L]
# Disable directory browsing
Options -Indexes
|
|
|
| Back to top |
|
Stray78

Joined: 15 Apr 2024 Posts: 61 Location: USA
|
Posted: Sun 22 Mar '26 22:12 Post subject: |
|
|
| Yeah. You can use that. |
|
| Back to top |
|
edwardsmarkf
Joined: 20 Feb 2013 Posts: 29 Location: cottonwood, az
|
Posted: Sun 22 Mar '26 23:03 Post subject: |
|
|
thank you!
is there a way to make sure my syntax is correct, or is it best to just look in the apache log file? |
|
| Back to top |
|
Stray78

Joined: 15 Apr 2024 Posts: 61 Location: USA
|
Posted: Mon 23 Mar '26 0:32 Post subject: |
|
|
The syntax is correct. Just put it in a .htaccess file or in your config (in your config requires a restart). Test it by calling for files.
if it is not a .wav .mp3 .opus file it will fail. |
|
| Back to top |
|