WebTools

307 Useful Tools & Utilities to make life easier.

HTACCESS Redirect Generator

Generate HTACCESS Redirects

Enter the path you want to redirect from (e.g., /old-page)
Enter the destination path or full URL.
Redirects all HTTP traffic to secure HTTPS.

Generated .htaccess Code

Copy the generated code below into your .htaccess file.

Streamline Your Apache Server with the .htaccess Redirect Generator

Managing server-level redirects can be a tedious and error-prone process. A single syntax error in an Apache .htaccess file can result in infinite redirect loops or internal server errors that take your entire website offline. The .htaccess Redirect Generator provides a graphical, interactive interface to construct robust, error-free Apache rewrite rules instantly. Built using Alpine.js for reactive state management, the tool processes your configuration preferences entirely on the frontend and compiles them into standard mod_rewrite directives displayed in an embedded syntax-highlighted editor.

Deep Dive: How the Generator Constructs Rules

At its core, this utility is divided into two primary configuration scopes: Manual Redirects for specific URL paths and Global Rules for overarching domain behavior. When you click the submit button, the tool's underlying algorithm processes your active settings and constructs an array of Apache directives. It intelligently wraps all generated rules within an <IfModule mod_rewrite.c> block to ensure your site won't crash if the Apache rewrite module is disabled or unavailable. Furthermore, it automatically injects the necessary RewriteEngine On and RewriteBase / commands, ensuring a clean slate for the rules that follow.

Global Rules: Enforcing HTTPS and WWW Prefixes

The Global Rules tab allows you to enforce critical SEO and security policies across your entire domain without writing complex regular expressions.

  • Forcing HTTPS: If you toggle the Force HTTPS switch, the generator appends a condition to check if the connection is unencrypted (RewriteCond %{HTTPS} off). If true, it writes a rule redirecting all traffic to the secure equivalent (RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]), preserving both the host name and the requested URI while returning a permanent 301 status.
  • WWW / Non-WWW Resolution: Canonicalizing your domain is vital for search engine rankings. If you choose to force the "www" prefix, the tool uses a negative condition (RewriteCond %{HTTP_HOST} !^www\. [NC]) to catch any requests lacking "www" and redirects them accordingly. Conversely, if you prefer a non-www domain, it captures the raw domain string omitting the "www" prefix using a capture group (RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]) and forwards the user to the base domain using the %1 backreference variable. Both options append the [NC] (No Case) flag to ensure case-insensitive matching.

Configuring Specific URL Redirections

Under the Manual Redirects tab, you can set up targeted forwarding from one specific path to another. The tool's parser handles path normalization for you. If your "From" path does not begin with a forward slash (/), the tool automatically prepends it. Similarly, for the "To" path, it verifies if the input begins with either http or a forward slash; if it lacks both, a forward slash is prepended to ensure the relative path is valid.

The generator allows you to choose between a 301 Permanent or a 302 Temporary redirect. The tool binds your choice to the rule's flag parameter. It crafts a RewriteCond matching the exact requested URI (e.g., ^/old-page$) and then uses a catch-all RewriteRule ^(.*)$ to push traffic to your designated target path with the appropriate status code flag (e.g., [R=301,L]).

A Concrete Worked Example

Let's look at how the tool translates a set of complex requirements into clean Apache code. Suppose you are migrating your site and have the following requirements:

  1. You want to redirect an outdated pricing page from /pricing-2023 to your new secure domain at https://example.com/pricing.
  2. You want this to be a permanent redirect (301).
  3. You want to ensure all site visitors use an encrypted connection (Force HTTPS).
  4. You want to strip the "www" prefix from all incoming requests.

You would configure the tool as follows: set "From" to pricing-2023, "To" to https://example.com/pricing, and "Type" to 301. Under Global Rules, toggle "Force HTTPS" on, and set WWW Redirect to "Force Non-WWW".

When you generate the code, the tool applies its path normalization, recognizes the absolute URL in the "To" field, and outputs the following exact block:

# Generated by HTACCESS Redirect Generator

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    # Force HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Force Non-WWW
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
    # Custom Redirect
    RewriteCond %{REQUEST_URI} ^/pricing-2023$ [NC]
    RewriteRule ^(.*)$ https://example.com/pricing [R=301,L]
</IfModule>

This code is displayed within a high-performance Ace Editor instance, complete with Apache syntax highlighting (using ace/mode/apache_conf) and an integrated clipboard copy button for seamless deployment to your server environment.

Frequently Asked Questions (FAQs)

Does the generator overwrite existing rules if I copy-paste the output into my .htaccess file?
The generator creates a complete, standalone <IfModule mod_rewrite.c> block. If you already have an .htaccess file, you should append this block carefully or merge the specific RewriteCond and RewriteRule directives into your existing mod_rewrite section to prevent duplicate RewriteEngine On declarations from causing conflicts.
Why does the tool automatically add forward slashes to my custom redirect paths?
To ensure valid Apache syntax, the underlying script checks if your "From" and "To" inputs contain the necessary prefix. If "From" lacks a /, the tool injects one so the regex matches the absolute URI path properly. For the "To" field, if it doesn't start with http (indicating a full domain URL) or / (indicating a root-relative path), it prepends a slash to prevent the server from interpreting it as a broken relative file path.
What does the [L] flag in the generated rules mean?
The [L] (Last) flag tells the Apache server to stop processing any further rewrite rules if the current rule matches. The tool automatically appends this to both global rules (like forcing HTTPS) and your custom URL redirects to optimize server performance and prevent unintended looping rule chains.
Can I generate both 301 and 302 redirects simultaneously?
The current state of the generator processes one custom path redirection at a time. The dropdown allows you to select either a permanent (301) or temporary (302) status code for the single "From" and "To" configuration you provide. If you need multiple custom paths with varying status codes, you will need to run the generator multiple times and combine the resulting # Custom Redirect rule lines manually.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us