One redirect per line: old-path → new-url [code] — e.g. /old /new 301 or /a https://example.com/b
# .htaccess — generated output will appear here # Click "Add" on any section above to build your rules
What is .htaccess?
.htaccess is a per-directory configuration file for Apache web server. Place it in your website root (or any directory) to configure redirects, URL rewrites, security, caching, and more without editing the main server config.
Redirect vs Rewrite
Redirect (Redirect 301 /old /new) tells the browser to go to a new URL. The browser makes two requests — the client sees the new URL.
RewriteRule rewrites the URL internally on the server — the browser sees the original URL but the server serves different content. Used for clean URLs, removing extensions, etc.
Status Codes
301 Permanent — Browsers and search engines cache this. Use when permanently moving a page.
302 Temporary — Not cached. Use when a page is temporarily at a different location.
307/308 — Like 302/301 but preserve the HTTP method (POST stays POST after redirect).
mod_rewrite
RewriteRules use PCRE regex. Key flags: [L] = last rule (stop processing), [R=301] = redirect, [NC] = case-insensitive, [QSA] = append query string.
Test with: curl -I https://yoursite.com/old-path and look for the Location: header.
Requirements
mod_rewrite must be enabled: sudo a2enmod rewrite and your Apache config must have AllowOverride All for the directory.