I wouldn’t use htaccess for that.
What I would do is make a ‘download page’ template and use it to ‘serve’ the files.
By doing that, I can do a check with is_user_logged_in()
Codex and redirect with wp_login_url()
Codex
Just do:
if ( is_user_logged_in() ) :
//file link
else :
wp_login_url();
endif;
I think it’s easier and safer to do that. Besides, you can even make that into a plugin later and use it on another projects or keep using it if you change your site template.
Related Posts:
- How to change old permalink?
- Setting up WordPress with Custom Permalinks and no .htaccess File?
- Does WordPress Change the .htaccess File When Updating?
- How to use relative links on my pages?
- How can I store page ID in a post instead of other selected permalink?
- Move WordPress to subdirectory, keep ALL URLs
- 301 Redirects for Changed Permalink Structure & Category Base
- Permalinks to Custom does not work (out of box)
- WordPress permalinks Yahoo hosting(no .htaccess allowed)
- How do I turn off 301 redirecting posts (not canonical)?
- Permalink Issues by Installing WordPress in Subdirectory / Subfolder
- Passing variables through permalink structure
- WordPress on a subdirectory of Laravel – WordPress pretty permalinks inner page shows laravel
- How to get a page url by a page id?
- How to map permalinks with accented letters to sanitized slugs?
- Remove subfolders from URL
- Changing Permalinks to a Custom Permalink causes a 404 Error [no matter what I do]
- Why does WP not use relative links when linking pages?
- Menu Link Redirect Based on Username or User ID
- Social Media Links on homepage – within posts/post loop
- htaccess or redirect to cloak portion of a link?
- WordPress overrides the GET variables, (page_id) set in HTACCESS
- custom naming of search permalink /search/
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Changing URL from /%postname%/%post_id to /%category%/%postname%/%post_id%
- Using only %postname%
- Change website URL without breaking links or images? WP 3.3
- removed index.php now all pages 404
- Rewriting search permalink
- removing index.php IIS 7.5 webconfig
- Rewrite rule never matching
- wordpress permalinks tweeks
- Getting a 500 internal server error ONLY on wp-admin/options-permalink.php
- Custom url for a single page
- Using WP rather than .htaccess to redirect pages/posts
- .htaccess – Redirect duplicated post ended in ‘-number/’ to the same url without the -number/
- What happens when permalink settings are updated?
- WordPress redirection problem after moving to a new server?
- Change of permalink structure – redirects in htaccess breaks the archive links
- After moving from subdirectory to home, home page does not display
- Specific URL Rewriting with parameters in wordpress
- WP Site in subdirectory Joomla! Site – Permalinks not working
- Rewrite my default post URL
- How can I make my .htaccess file writeable by wp-admin?
- I copied my site to another site but all links point to old site
- 404 with post name permalinks
- Best way to add internal link in widget
- Confusion about how a URL is being parsed
- Problems redirecting to “pretty” permalinks (wordpress in Subdirectory)
- .htaccess file missing from WordPress install directory
- Why does chrome keep downloading a file instead of running the site?
- Permalinks: Page Not Found
- How to protect htaccess so it can’t be overwritten?
- Permalinks not working
- Changes to .htaccess not updating the file (old rules still take effect)
- If I change permalink structures, can I use htaccess to permanantly redirect links?
- Redirect parent taxonomy to it’s child
- AWS WordPress Install – pages/posts 404 on restart until updating permalinks
- WordPress 404 in development area
- Need Help Correct Regular Expression Redirect Code
- Permalinks settings page blank
- Automatically append ID to at the end of specific URLs
- 301 Redirects Result in 404 for WordPress Search Query Strings
- After updating to 4.8 permalinks will not work (all 404)
- Custom Permalink
- Change in permalink structure made javascript cookie not work correctly
- Permalinks not working with Vagrant
- Only default permalink is working mod_rewrite enabled
- why some permalinks adding characters/ruining links
- How to redirect to correct pages after permalink structure change
- How do I add /blog/ as a prefix to permalink structure for posts, categories & tags?
- Only plain permalinks working
- WordPress Sub domain
- Page preview is shown, updating page gives 404 error
- Redirect Uploads Folder to Query Vars in WordPress
- WordPress url ingore permalinks setting [closed]
- Redirect a Blogger Page URL to wordpress
- URL rewriting: removing the site’s basename for a specific category
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- How to eliminate permalink prefix in WordPress Multisite
- Redirecting all posts after changing URL structure with htaccess
- Get the url of a page template without using the page slug and ID
- Redirect all posts permalinks from “.html” to “/”
- flush_rewrite_rules breaks permalinks
- WordPress 4.4 old permalink redirect
- Htaccess https 301 problem
- How to generate a list of all urls
- Accessing Subdirectories in WordPress Install
- Empty permalinks settings in .htaccess
- How to rewrite a URL to another rewritten URL without changing the address?
- An other permalink problem – 404 Error
- WordPress Not Using Template Files After Permalink Update
- How to use different domains for different blogs hosted in the same host in subdomains with .htaccess
- WordPress 3.1 .htaccess contents keep dissappearing?
- Custom permalinks in WordPress
- Allow Permalinks to Work with and without Hyphens
- How to prevent WP overwriting my custom htaccess rewrites?
- mod-rewrite exception? keep #hash in matching urls?
- What causes /pages/ to appear in URI, and how to remove it?
- Format HTTP links