RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^wp-content/uploads/([^/]*\.(pdf|zip))$ filecheck.php?file=$1 [QSA,L]
This actually looks OK, except if you have additional subdirectories within the /uploads directory? An alternative is to include an additional condition on the original rule that only rewrites the request if the request ends in .pdf or .zip. For example:
RewriteCond %{REQUEST_URI} \.(pdf|zip)$ [NC]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]
It shouldn’t really matter, but make sure this goes before the WordPress front-controller.
Related Posts:
- Password protect some uploaded files, so only logged-in users can view them
- How to protect uploads in multisite if user is not logged in?
- How to Protect Uploads, if User is not Logged In?
- Extend Media Library
- WordPress 3.5: Setting custom “full URL path to files” in the Media Library?
- How to show all available images in WP’s media library when using the Polylang plugin?
- Which filters or actions to use after a media upload and delete?
- How to wp_upload_bits() to a sub-folder?
- “Add Media” only shows “Full Size” under Attachment Display Settings
- Where do the favicons for Media Files come from
- Is it possible to trigger some JavaScript when Media Popup is opened?
- How to call WP3.5 Media Library manager?
- Append button to WordPress Image Details modal
- WP3.5 Media Uploader – how to make it accept multiple images?
- How to disable WordPress Media resize different size version?
- Media library storing files in uploads not folders within in uploads
- Add select field to media uploader that adds a class to the image
- How to host different file formats/types for a media attachment without creating multiple attachments?
- Site icons with alpha channel for self-hosted WordPress blog network
- How do I get allowed Media Library upload file extension list?
- Cannot upload .mp3 file to wordpress media
- Switch between tabs on “Insert Media” dialog
- Restrict WordPress Media Library for a specific user role (users can only see/select own media)
- Display attachments by the ID of the post being edited in the wp.media frame (frontend)
- move_uploaded_file() not working on wordpress front end
- WordPress Issue : The uploaded file could not be moved to wp-content/uploads/
- Convert (-) and (escape) signs to (_) when uploading files on wordpress media library automatically
- Using wp_enqueue_media() with switch_to_blog() issue
- making media URL secured
- How to get the return value of wp.media({ frame: ‘post’ }) in all cases?
- Media library only shows for admin. Doesn’t show editor or below [closed]
- Is it safe to allow non-admin users access to media uploader
- upload_max_filesize is set to 64 MB already but WordPress is still showing 2 MB
- PHP error when trying to upload .mp3 files via Media Library [closed]
- A link (not in the post) to download a specific PDF file
- Migrating media files (documents only) to a fresh install and maintaining the same directory structure
- How does wordpress handle media files?
- WordPress media upload issue could not insert attachment into the database
- Thumbnail images missing in WP media library
- Open Media Uploader Link in single post or page
- Remove Media File Items From Server That Do Not Exist in Media Library
- Add SWF file to wordpress through custom template
- What if I have a large file on the server that I want the wp library to have?
- Uploaded images result in a file url with full path on disk appended
- Using WP-CLI “wp media import” to sync files to the media library
- Efficient way to move media folder to another folder
- Make inline uploader (plupload) on options page upload to a specific folder
- Images not displaying on site or media library
- Replicate Media Galley Edit view in Add Media View
- How to Protect Uploads, if User is not Logged In?
- Front-End Upload media with category
- How to manually set an attachment in a post?
- Media Library: Remove replace images of selected author
- Adding attachment custom field metadata to TinyMCE tag
- How to upload multiple images using WP rest API to media?
- Media not displaying other users uploads – WordPress 4.9.2
- Organizing the Media Library for Cleanup
- Issues with WordPress 3.9.6 media libraries on XAMPP
- Insert media while posting is not working with new wordpress update
- controlling whether upload is attached to post or not
- How to split my uploaded media into directories?
- wordpress 3.6 media manager cropping timestamp
- Image in binary in the data to WordPress media library
- How to Upload a media item with alt text and description
- Different upload file size limits based on file type
- wp-content/uploads/year/month returns 404
- simple solution for restricting access to (some) uploads/downloads
- Media not actually deleted on disk when click “Permanent Delete”
- Add inline uploader to plugin option page
- Differentiate Featured Image from Post Images upon Upload
- What might cause a POST to wp-admin/async-upload.php to return JSON >and< HTML?
- Media Uploader: get deleted files
- How to get the image url in the input box from media library?
- How to import 55k images (uploaded via FTP) into WordPress Media libary? [closed]
- Allow only attachment uploaded to current post
- Use the WP media uploader dialog for uploading a form attachment (non-admin). Offering progress and drag and drop feedback
- Cannot upload anything via wordpress
- Use custom image size in admin panel
- WordPress media uploader – upload tabs not hiding
- How to fix the orientation of images when uploading via the WordPress Media Uploader? [closed]
- Cropping thumbnails to specific dimensions on front end post
- How to add HTML into error message
- media file uploading
- What is wrong with my wp_insert_attachment code?
- Organising and display thousands of photos in media library
- Drag and Drop Media Not Working in Windows 10 Edge Browser
- Exclude some photos in media library
- Failed to load resource at admin screen
- Upload more than one media files with a post
- Image uploaded in media library, can only see it when I using the WP Edit Image feature. 404 when trying to view in browser
- Single file upload
- Host Images from Link
- Can’t upload files 1MB+ [closed]
- Blurry Images WordPress 5.8.1
- Updating Media Library PDF’s in bulk
- Assign multiple categories to Media Library upload
- upload image to wordpress media library failed for custom post type
- Cannot add image (png, jpeg, etc.) but can add pdf, 403 forbidden when posting
- Add URL in image upload error message
- wp.media multiple selection limit