.htaccess Redirect Builder
Generate error-free Apache .htaccess code for 301 redirects, HTTPS enforcement, and canonical URL routing.
Updated
What is the .htaccess Redirect Builder?
Managing URL redirects is a critical task for maintaining website SEO, preserving link equity, and ensuring a seamless user experience during site migrations. If your website runs on an Apache server, the .htaccess file is the central command center for these routing rules.
However, writing .htaccess rewrite rules manually can be incredibly finicky. A single misplaced character, an unescaped regex string, or a misunderstood leading slash can instantly result in the dreaded 500 Internal Server Error, taking your entire website offline.
The .htaccess Redirect Builder takes the guesswork and risk out of server configuration. It provides a visual, intuitive interface to generate syntactically perfect, highly optimized Apache mod_rewrite rules. Whether you need to enforce a global HTTPS protocol, standardize your WWW canonical domain, or map dozens of old URLs to new destinations using 301 permanent redirects, this tool compiles your requirements into clean, well-commented code ready to be pasted directly into your server environment.
How it works
Using the .htaccess Redirect Builder is designed to be a straightforward process, abstracting away the complex syntax of Apache's mod_rewrite engine.
1. Configure Global Canonical Rules
Start by setting the foundation of your website's routing structure using the Canonical & Server Enforcements panel.
- Force HTTPS: Check this box to automatically redirect all standard HTTP traffic to secure HTTPS.
- WWW Preference: Choose whether your site should force the
www.prefix (e.g.,www.example.com), strip it (e.g.,example.com), or ignore it entirely. Uniformity here prevents duplicate content penalties from search engines. - Trailing Slashes: Decide if your URLs should consistently end with a trailing slash (
/) or not. - Server Tweaks: You can also disable directory indexing (to protect your file structure from public view) or define a custom 404 error page path.
2. Add Custom Path Redirections
For specific page migrations, use the URL Routing & Path Redirection section. Click "Append New Path Mapping" to create a new rule row.
- Match Strategy: * Exact Match: Redirects exactly the specified URL path (best for individual pages).
- Directory Prefix: Redirects a folder and seamlessly passes everything that follows it to the new destination (e.g.,
/old-blog/post-nameto/new-blog/post-name). - Regex: Advanced matching using regular expressions for complex, pattern-based routing.
- Source/Target: Enter your old relative path (e.g.,
/old-page) and your new destination (e.g.,/new-pageorhttps://other-domain.com). - HTTP Code: Select 301 for permanent moves (passes SEO value) or 302 for temporary changes.
3. Copy Your Generated Code
As you adjust settings and add rules, the tool instantly compiles the underlying code in the Generated Code Output box. The output is structured logically and heavily commented so you know exactly what each block does. Simply click the copy icon, open the .htaccess file in your website's root directory via FTP or your hosting file manager, and paste the code.
Examples
Simple Page Migration (301 Redirect)
Redirecting a deleted or moved page to its new URL permanently to preserve SEO rankings.
Directory Prefix Routing
Forwarding all traffic from an old blog subfolder to a new subdomain.
Global HTTPS Enforcement
Configuring the server to automatically upgrade all unencrypted HTTP traffic to secure HTTPS.
Frequently asked questions
What is an .htaccess file?
What is an .htaccess file?
An .htaccess (Hypertext Access) file is a configuration file used by Apache web servers. It allows you to control server behavior on a directory level without needing access to the main server configuration files. It is commonly used for URL redirection, password protection, custom error pages, and altering caching behavior.
What is the difference between a 301 and 302 redirect?
What is the difference between a 301 and 302 redirect?
A 301 redirect is a permanent redirect. It tells search engines that a page has permanently moved to a new location, and it transfers the SEO ranking power (link equity) from the old URL to the new one. A 302 redirect is temporary; it redirects users to the new page but tells search engines to keep the old URL in their index because the move is not permanent. You should almost always use a 301 redirect for site redesigns or page changes.
Where do I place the generated code?
Where do I place the generated code?
You should place the generated code inside the .htaccess file located in the root directory of your website (typically public_html, www, or htdocs). If the file does not exist, you can create a new plain text file, name it exactly .htaccess (don't forget the leading dot), and paste the generated code inside.
My site broke and shows a 500 Internal Server Error. What happened?
My site broke and shows a 500 Internal Server Error. What happened?
A 500 Internal Server Error immediately after editing an .htaccess file means there is a syntax error or a conflict in the rules. This can happen if your server does not have the mod_rewrite module enabled, or if the generated rules conflict with existing code (like WordPress default permalink structures). To fix it, connect to your site via FTP and remove or rename the .htaccess file to restore access, then carefully review your rules.
Does this tool fix the "leading slash" Apache bug?
Does this tool fix the "leading slash" Apache bug?
Yes. In per-directory configurations (which is what .htaccess is), Apache automatically strips the leading slash from the requested URI before evaluating RewriteRule patterns. A common mistake is writing RewriteRule ^/old-page$ /new-page. This tool automatically normalizes your inputs, removing the leading slash for exact and prefix matches so the rules work perfectly on the first try.
Should I place these rules above or below existing code like WordPress defaults?
Should I place these rules above or below existing code like WordPress defaults?
Generally, custom explicit redirects and canonical enforcements (like forcing HTTPS) should be placed above CMS-specific routing rules like the default WordPress block. Apache processes rules from top to bottom. If WordPress processes the URL first, your custom redirects might be ignored or cause a routing loop.
Related tools
More utilities you might find handy.
.env File Generator
Quickly generate clean, properly-quoted .env files from key-value pairs — no more quoting errors or broken deployments.
ASCII Converter – Text to ASCII, Hex, Binary & Back
Convert text to ASCII codes and decode back in decimal, hex, binary, or octal — live, private, and 100% browser-based.
Binary Logic Gate Simulator
Simulate AND, OR, NOT, XOR, NAND, NOR, XNOR gates with interactive inputs and full truth tables.