SEO
Apache .htaccess redirect cheatsheet — patterns that ship
Apache .htaccess redirect snippets for the patterns you actually need — Redirect directive, RewriteRule, regex captures, section moves. Copy and ship.
10 April 2026 · 2 min read
Quick frame: Apache .htaccess redirect patterns split between simple Redirect directives (no regex) and RewriteRule patterns (regex-capable). Use the simpler one when it fits; reach for RewriteRule only when you need capture groups.
Pattern 1: simple page move
Redirect 301 /old-page /new-page
The simplest possible redirect — exact match, status code, target. Use this whenever you can.
Pattern 2: full URL move
Redirect 301 /old-page https://www.example.in/new-page
Same syntax, with full URL on the right. Useful for cross-domain redirects.
Pattern 3: regex with capture
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^old-blog/(.*)$ /blog/$1 [R=301,L]
</IfModule>
$1 captures the wildcard, [R=301,L] sets 301 status and stops further rewriting.
Pattern 4: apex to www
RewriteCond %{HTTP_HOST} ^example\.in$ [NC]
RewriteRule ^(.*)$ https://www.example.in/$1 [R=301,L]
Pattern 5: http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Pair with HSTS header for full protection.
Pattern 6: trailing slash
Add trailing slash:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [R=301,L]
Strip trailing slash:
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]
Pattern 7: bulk page moves
For dozens of one-to-one moves, prefer many simple Redirect lines over one giant regex:
Redirect 301 /old-page-1 /new-page-1
Redirect 301 /old-page-2 /new-page-2
Redirect 301 /old-page-3 /new-page-3
Easier to maintain, easier to audit.
Performance considerations
Apache reads .htaccess on every request unless AllowOverride None is set and rules are moved into vhost. For high-traffic sites, prefer vhost-level redirects. For shared hosting (where vhost is inaccessible), .htaccess is fine.
After deploying
.htaccess changes take effect immediately — no Apache restart needed. Always verify with the redirect chain visualiser to confirm zero unintended chains.
Use the .htaccess redirect generator to author rules cleanly from a URL list. For nginx equivalents, see nginx redirect rules cheatsheet.
FAQ
Q. Should I use Redirect or RedirectMatch?
A. Redirect for exact match, RedirectMatch for regex without capture, RewriteRule when you need capture groups. Use the simplest one that fits.
Q. Why isn't my .htaccess working?
A. Check that AllowOverride All is set in the Apache vhost config. Some hosts default to AllowOverride None which silently disables .htaccess.
Q. Can I redirect based on cookies or query parameters?
A. Yes, via RewriteCond. Useful for A/B testing or geo-redirects.
Try the free tool
.htaccess Redirect Generator
301 / 302 rules for Apache with regex helper and trailing-slash toggle.
Open .htaccess Redirect Generator →