Free .htaccess Redirect Generator
Generate Apache .htaccess redirect rules for 301, 302, and other redirect types. Force HTTPS, WWW, and more โ no server knowledge needed.
What Is .htaccess?
The .htaccess file (short for "hypertext access") is a distributed configuration file used by Apache web servers. It allows website owners and developers to apply server-level configuration directives on a per-directory basis without modifying the main Apache server configuration file (httpd.conf). When Apache processes a request for a file in a directory, it reads the .htaccess file in that directory (and all parent directories up to the document root) and applies any directives found there.
The .htaccess file supports a wide range of functionality: URL redirects and rewrites, password protection with HTTP Basic Authentication, custom error pages (404, 500 etc.), MIME type overrides, GZIP compression settings, browser caching headers, and access control rules that allow or deny traffic from specific IP addresses. For most shared hosting users who do not have access to the main server configuration, .htaccess is the primary tool for server-level customization.
The name begins with a period (dot), which makes it a hidden file on Unix/Linux systems. If you are uploading via FTP, you may need to enable "show hidden files" in your FTP client to see and edit it. The file has no extension โ it is simply named .htaccess with no suffix.
301 vs 302 Redirect โ Which Should You Use?
The most common redirect types are 301 (Permanent) and 302 (Temporary), and choosing correctly between them has significant SEO implications. A 301 redirect signals to search engines that the original URL has permanently moved to the new location. Search engines transfer the majority of the original page's link equity (PageRank) to the new URL and update their index to reflect the new address. Use 301 redirects when you are permanently changing a URL, migrating content, or restructuring your site.
A 302 redirect signals that the move is temporary โ the original URL is still the canonical address and should be retained in the search engine index. Search engines do not transfer link equity for 302 redirects. Use 302 redirects only for genuinely temporary situations: A/B testing, seasonal content swaps, or maintenance pages. Using a 302 when you mean a 301 is a very common SEO mistake that can cause the old URL to continue ranking instead of the new one.
The 307 and 308 redirect types are HTTP/1.1 alternatives that guarantee the HTTP request method is preserved โ a POST request to a 307/308 URL will remain a POST to the new URL, rather than being converted to a GET (which older 301/302 implementations sometimes did). For most web content redirects (pages, images, assets), 301 and 302 are the correct choices. Use 307/308 only when working with form submissions or API endpoints where method preservation matters.
How to Force HTTPS with .htaccess
Redirecting all HTTP traffic to HTTPS is one of the most important security and SEO configurations for any website. Since 2014, Google has used HTTPS as a positive ranking signal, and modern browsers display "Not Secure" warnings for HTTP sites. The standard .htaccess rule for forcing HTTPS uses mod_rewrite:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The RewriteCond line checks whether the current request is not already using HTTPS. The RewriteRule then redirects all non-HTTPS requests to the same URL but with the https:// scheme. The [L,R=301] flags mean: stop processing rules (Last) and send a 301 Permanent Redirect. Make sure your SSL certificate is installed and working before adding this rule, otherwise you will create a redirect loop.
How to Force WWW or Remove WWW
Consistency between the www and non-www version of your domain is important for both SEO and user experience. Search engines treat https://example.com/ and https://www.example.com/ as separate URLs. If both versions are accessible without a redirect, you may accumulate duplicate content issues and split your link equity across two versions of your site.
Use the "Force WWW" preset to redirect all non-www traffic to www, or the "Remove WWW" preset for the opposite. You should also set your preferred version in Google Search Console under Settings > Change of Address, and ensure your canonical tags consistently reference the preferred version. The choice between www and non-www is largely a matter of preference โ www was historically preferred because it allows more flexible DNS and CDN configuration, but non-www is increasingly common for modern websites.
Common .htaccess Rules
Beyond redirects, .htaccess is used for many other server configuration tasks. Custom 404 error pages improve user experience by providing navigation options when a page is not found: ErrorDocument 404 /404.html. Directory listing protection prevents Apache from displaying a file browser when no index file exists: Options -Indexes. GZIP compression improves page load speed by compressing text-based assets before sending them to the browser. Browser caching headers tell visitors' browsers to cache static assets locally, reducing repeat visit load times.
Password protecting a directory is done with AuthType Basic, AuthName, AuthUserFile, and Require valid-user directives. IP-based access control uses Order deny,allow, Deny from all, and Allow from [IP] syntax (or the newer Require ip syntax in Apache 2.4+). Always keep a backup of your .htaccess file and test changes in a staging environment first โ a syntax error in .htaccess returns a 500 Internal Server Error for every request to that directory.
Frequently Asked Questions
curl -I http://old-url.com/old-page to see the response headers. Online tools like redirect-checker.org or httpstatus.io let you trace full redirect chains. Google Search Console's URL Inspection tool shows how Googlebot sees the redirect and whether it has been indexed.Related Free Tools
Need a custom tool built for your business?
Get a Free Quote