Apache .htaccess 301 Redirect Guide & Rewrite Rules
A comprehensive developer guide to configuring server-side 301 and 302 redirects in Apache using .htaccess and mod_rewrite.
What is an Apache .htaccess Redirect?
An .htaccess file is an Apache web server configuration file that allows directory-level configuration changes. Configuring 301 (Permanent) redirects at the .htaccess level is the fastest and most SEO-friendly way to forward web traffic, preserve search rankings, and pass link equity (PageRank) to new URLs.
1. Redirect Single Page (mod_alias)
The simplest way to redirect a specific URL to another path or external website:
2. Redirect an Entire Directory / Folder
Redirect all requests inside a subfolder to a new directory while keeping file paths intact:
3. Force HTTPS (SSL Encryption)
Ensure all visitors and search bots use the secure https:// protocol:
4. Force WWW Canonical Domain
Consolidate non-www traffic to www so search engines do not index duplicate versions:
5. Redirect Entire Old Domain to New Domain
When rebranding or migrating your website to a new domain name:
Generate .htaccess, Nginx, PHP, and HTML redirect code automatically with our Redirect Code Generator.