DNSfinder.net
Apache mod_rewrite

.htaccess Redirect Generator

Choose a redirect type, fill in the old and new locations where the rule needs them, and the generator writes the matching Apache directives for your .htaccess file. Nine rule types are covered: redirecting one page, moving a whole site to a new domain, forcing HTTPS, forcing or removing www, redirecting a folder, adding or removing trailing slashes, and hiding .html or .php extensions. Each rule can be 301 or 302, several rules can be stacked, and RewriteEngine On is added whenever a rule needs mod_rewrite.

Loading .htaccess Redirect Generator...

Querying live edge resolvers and network infrastructure...

How to use the .htaccess Redirect Generator

  1. Pick a rule type from the drop-down. The default is Force HTTPS with a 301.
  2. For page, domain and folder rules, fill in the old path or domain and the new destination. The placeholders show the expected shape.
  3. Choose 301 Permanent or 302 Temporary per rule, then click Add rule to stack more. The trash icon removes a rule.
  4. Copy the generated block and paste it near the top of the .htaccess file in your site's document root, then test in a private window.

What to look for

Redirect versus RewriteRule

The single-page rule uses mod_alias's Redirect directive, which matches by path prefix: Redirect 301 /old also catches /old-news. Every other rule uses mod_rewrite with RewriteCond and RewriteRule, so the output starts with RewriteEngine On whenever one of them is present. Both modules are enabled on nearly all shared hosting.

The HTTPS rule is proxy-aware

Behind Cloudflare or a load balancer the connection to Apache is often plain HTTP, so a naive HTTPS check loops forever. The generated rule tests both HTTPS off and X-Forwarded-Proto not equal to https before redirecting, which stops the loop while still redirecting visitors who arrived over http.

Test with 302, publish with 301

Browsers cache a 301 aggressively and keep following it even after you remove the rule, which makes mistakes painful to undo. Set the rule to 302 while you confirm it behaves, switch to 301 once it is right, and remember that a 301 is what passes ranking signals to the new URL.

Guide

Writing Apache redirects that do what you expect

What each rule type generates

Redirect one page emits Redirect 301 /old-page.html https://example.com/new-page/, with the old value reduced to a path and the new value used as given. Move whole site matches the host with RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC] and sends every request to the new base with the path preserved by $1. Redirect a folder turns ^old-folder/(.*)$ into /new-folder/$1, so deep links survive the move.

Force HTTPS, Force www and Remove www are host-level rules that use %{HTTP_HOST} and %{REQUEST_URI} so they work for any path. The www rules hard-code https:// in the target, which assumes your certificate covers both names. If it does not, fix the certificate before publishing. Remove www captures the bare host with ^www\.(.+)$ and reuses it as %1.

The trailing-slash rules check the filesystem first: Remove trailing slash skips real directories with !-d, and Add trailing slash skips real files with !-f, so /images/ and /style.css keep working. Hide extension is two parts: a redirect from /page.html to /page driven by %{THE_REQUEST}, and an internal rewrite that serves page.html or page.php when the extension-less file exists.

Order, flags and where the file goes

Apache evaluates .htaccess rules top to bottom and the L flag stops processing at the first match, so order matters. Put the HTTPS and www rules first so every later redirect already lands on the canonical host, then page and folder redirects, then the cosmetic trailing-slash and extension rules. The generator outputs rules in the order you added them, so arrange them that way.

The file belongs in the document root (often public_html or htdocs), and the server must allow overrides: AllowOverride FileInfo or All in the virtual host, which shared hosts enable by default. If a redirect never fires, that setting or a disabled mod_rewrite is the usual cause. Apache reads .htaccess on every request, so there is no restart, and a syntax error produces a 500 on the whole site until it is fixed.

  • R=301 or R=302 sets the status; L stops further rules; NC makes the host match case-insensitive.
  • Query strings are carried over to the new URL by both Redirect and RewriteRule unless you end the target with ?.
  • In .htaccess context the leading slash is stripped before matching, which is why the patterns start with ^ and no slash.

Redirect loops and other failures

A loop means two rules keep sending the request back to each other, or one rule matches its own output. The classic case is forcing HTTPS behind a proxy that terminates TLS: Apache sees HTTP, redirects to https://, the proxy forwards HTTP again. The generated rule's X-Forwarded-Proto check prevents this, but only if the proxy sets that header. Cloudflare and most load balancers do.

To debug, keep the rule on 302, test in a private window so cached 301s do not interfere, and use curl -I to read the Location header of each hop. If a redirect works for the home page but not for deep URLs, a later rule with L is probably catching them first. If it works nowhere, check AllowOverride. Remove rules one at a time until the behaviour changes.

Chains are the quieter problem. http://old.com/page should arrive at https://www.new.com/page in one hop, not three. After a domain move, put the HTTPS and www rules on the new domain and make the old domain's rule target the final https://www form directly. Broken Link Checker lists every redirected link on a page along with its final URL, which is a quick way to spot chains.

When .htaccess is the wrong place

Nginx does not read .htaccess at all, and IIS uses web.config. For clean-URL rewrites on those servers, URL Rewrite Generator writes the equivalent location block or web.config rule. Static hosts and CDNs have their own redirect files or dashboards, and a redirect configured at the edge saves a round trip to the origin.

Even on Apache, a site with hundreds of one-page redirects is better served by a RewriteMap or by rules in the main server configuration, which is parsed once rather than on every request. For a handful of rules on shared hosting, which is what most people need, .htaccess is fine and the generator's output is enough.

Knowledge Base & FAQ

.htaccess Redirect Generator FAQs

Common questions about the .htaccess redirect generator.

In the document root of the site, the folder that holds your index file. On shared hosting that is usually public_html or www. Create the file if it does not exist, keep the leading dot, and make sure your file manager shows hidden files. Rules in a subfolder's .htaccess apply only to that folder and below.