htaccess redirect downloads; Looking to redirect file downloads to the latest version? When you offer downloadable files such as software installers, utilities, or documents, older versions often remain bookmarked, shared, or indexed by search engines. This can lead to confusion, support issues, and users running outdated or insecure software.
In this simple solution, I show you how to use .htaccess rules to automatically redirect all download requests for older file versions to the most recent release. This ensures visitors always receive the latest file, no matter which versioned link they request. For example, requests for files ranging from filename-0.0.0.1.exe through filename-2.0.0.8.exe will all be redirected to filename-2.0.0.9.exe.
How to Use htaccess to Redirect Downloads

There are two common ways to handle download redirects in Apache:
- Using RewriteRule (mod_rewrite)
- Using RedirectMatch (mod_alias)
Both methods are shown below so you can choose the one that best fits your setup.
Note: These examples assume your files are located in the /downloads/ directory. If your files live elsewhere, update the paths accordingly. Replace filename with your actual file name. The examples also assume a four part version number format: x.x.x.x.
Redirect Downloads Using RewriteRule
The most flexible method is using mod_rewrite. This allows precise matching with regular expressions and works well for versioned files.
RewriteEngine On
RewriteBase /downloads/
RewriteRule ^filename-(\d+\.\d+\.\d+\.\d+)\.exe$ filename-2.0.0.9.exe [R=307,L]
This rule works as follows:
- RewriteEngine On enables the rewrite engine
- RewriteBase /downloads/ sets the working directory
- The pattern matches any file named filename-x.x.x.x.exe
The regular expression (\d+\.\d+\.\d+\.\d+) matches four numeric version segments separated by dots. This captures any version number without needing to list them individually.
All matching requests are redirected to filename-2.0.0.9.exe, regardless of the requested version.
The flags used:
- R=307 sends a temporary redirect
- L stops further rule processing
If you want the redirect to be permanent, you can change 307 to 301. Use 301 only when you are certain the old versions will never return.
Redirect Downloads Using RedirectMatch
If you prefer a simpler approach and do not need advanced rewrite logic, RedirectMatch can also handle this task.
RedirectMatch 307 ^/downloads/filename-\d+\.\d+\.\d+\.\d+\.exe$ /downloads/filename-2.0.0.9.exe
This directive matches any request for a versioned file in the downloads directory and redirects it to the latest release.
Key points:
- RedirectMatch uses regular expressions
- ^ and $ anchor the match to the full path
- \d+ matches one or more digits
As with the RewriteRule example, you may replace 307 with 301 if you want a permanent redirect.
Which Method Should You Use?
- Use RewriteRule if you already rely on mod_rewrite or need more control
- Use RedirectMatch for simple, lightweight redirection
Either approach ensures users always receive the latest file version, reduces support headaches, and prevents outdated downloads from lingering in the wild.
Once configured, you can release new versions without worrying about old links breaking or serving obsolete files.