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?
- How to use relative links on my pages?
- 301 Redirects for Changed Permalink Structure & Category Base
- 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?
- Remove subfolders from URL
- Why does WP not use relative links when linking pages?
- Menu Link Redirect Based on Username or User ID
- htaccess or redirect to cloak portion of a link?
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Using only %postname%
- removing index.php IIS 7.5 webconfig
- wordpress permalinks tweeks
- .htaccess – Redirect duplicated post ended in ‘-number/’ to the same url without the -number/
- After moving from subdirectory to home, home page does not display
- Specific URL Rewriting with parameters in wordpress
- Rewrite my default post URL
- Best way to add internal link in widget
- Problems redirecting to “pretty” permalinks (wordpress in Subdirectory)
- .htaccess file missing from WordPress install directory
- Permalinks: Page Not Found
- 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
- Automatically append ID to at the end of specific URLs
- Permalinks not working with Vagrant
- Only default permalink is working mod_rewrite enabled
- 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
- Page preview is shown, updating page gives 404 error
- Redirect Uploads Folder to Query Vars in WordPress
- WordPress url ingore permalinks setting [closed]
- How to eliminate permalink prefix in WordPress Multisite
- Get the url of a page template without using the page slug and ID
- 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?
- 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
- What causes /pages/ to appear in URI, and how to remove it?
- Format HTTP links
- Changing WordPress routing to load the same page for different URLs
- cannot link a external url, present page url acting as parent url
- Can WP give a value a post ID?
- Some Pemalink problems, probably caused by wrong .htaccess configuration?
- Test site pages go to main site
- Strange behavior: random HTTP error 500 fixed by visiting Permalinks settings page (htaccess issue with language code)
- how to prefer static page if it exists over wordpress page
- Moved site, Old links in pages still pointing to old host
- change WordPress permalinks and redirect new urls 301
- How to use page jumps to top of banner and page title?
- Why will Pretty URLs not Work?
- WordPress Page Not Found if Permalink Settings is Postname
- Conditional Permalink based on category?
- Problems with permalinks (.htaccess not working)
- old permalinks not found
- What would cause a 500 Server Error with permalinks turned OFF?
- How can I see a list of all pages my WordPress site has generated?
- Change author permalink using htaccess?
- A dash can replace a period in a link, how to fix it
- Cannot publish posts or pages when I change permalink structure
- Can I link to content dynamically from a page to a new page?
- wordpress admin panel loop on nginx
- Find internal links to post
- rebuilding/ rewriting a url to make it SEO friendly
- Very strange behaviour related to htaccess and custom posts and custom posts substrings (BUG?)
- Remove link function from oembed image or video
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- My permalinks for all pages and posts now include old page titles as parents/categories
- WordPress All pages but home simply read “hello”
- WordPress pages break with custom permalink settings (theme directory not output)
- How to rewrite a folder in WordPress?
- LetsEncrypt WordPress on the Raspberry Pi – Nice url’s give 404 with https, http works
- On IIS, stop WordPress from resaving my web.config file when I enter the Permalinks config page
- Can’t access WordPress site in subfolder possibly because of .htaccess redirect from root installation?
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- Pretty permalinks (again)
- Fresh wordpress installation in sub-directory not accessible
- Folder Name and Category Name WordPress
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- After changing permalink settings, everything works fine except for the two most recent posts
- .htaccess not working in WordPress
- How do you put your own rules into .htaccess?
- Permalink structure as code in back-end?
- redirect old pages by .htaccess
- wp_get_attachment_url not working
- htaccess strip url
- Use .htaccess to redirect homepage to its permalink
- Make all internal links relative, or otherwise make a website accessible from multiple domains
- 301 Redirect posts to newly added categories
- Standard Htaccess directives disappear by themselves