.htaccess redirect generator

Build Apache redirect rules for a page, a list of pages, a folder, a domain move, or HTTPS with www or non-www in one hop. Test any URL against the rules before you paste them into your server.

  • 301, 302, 307 and 308 rules
  • Test URLs and see every hop
  • Runs in your browser only
Ready
Try:

Status code

Fill in the form to start

From —
To —
Rules
—
Lines
—
Hops
—
  1. Request
    Waiting for input
    What the visitor asks for
  2. Rule
    —
    First rule that matches
  3. Response
    —
    Status and Location header
  4. Lands on
    —
    Final address

Your redirect rules

Test a URL

Choose what you are moving and enter the addresses above. Each rule appears here with a plain-English explanation, ready to copy.

The .htaccess code0 lines
Paste at the top of .htaccess, above # BEGIN WordPress. Keep a backup of the old file.
# Your rules will appear here.
Test a URL against these rules

    Simulated in your browser with the same logic as the generated rules. Other rules on your server, plugins and caches can change the real result.

    How Apache reads redirect rules

    A few rules of the road explain almost every redirect that does not behave.

    Top to bottom, first match wins

    Apache checks the rules in order. The L flag stops at the first rule that matches, which is why redirects must sit above the WordPress block that sends everything to index.php.

    Conditions belong to the next rule

    Each RewriteCond line applies only to the RewriteRule right below it. Host names, HTTPS and query strings are checked with conditions, because the rule itself only sees the path.

    The path has no leading slash

    In .htaccess, a request for /old-page/ reaches the rule as old-page/. Dots and other special characters must be escaped, which this tool does for you.

    Browsers remember 301s

    A permanent redirect can be cached by the browser for a long time. Test new rules in a private window, and use 302 while you are still unsure.

    Which status code to use

    What each redirect code tells browsers and search engines.

    CodeNameTypeSearch enginesForm POSTUse it for
    301 Moved Permanently Permanent Signals pass to the new URL May switch to GET Pages and sites that moved for good
    308 Permanent Redirect Permanent Signals pass to the new URL Kept (POST stays POST) Permanent moves of forms and API endpoints
    302 Found Temporary Old URL usually stays indexed May switch to GET Short campaigns, maintenance, A/B tests
    307 Temporary Redirect Temporary Old URL usually stays indexed Kept (POST stays POST) Temporary moves of forms and API endpoints

    How this tool works

    From the addresses you type to code you can paste.

    1. Pick what you are moving

      One page, a list of pages, a folder, a whole domain, or the HTTPS and www version of your site, plus the status code.

    2. Enter the old and new addresses

      Paths such as /old-page/ or full URLs. Pasted links are cleaned up, and an old address with ?query gets its own condition.

    3. The rules are built in your browser

      Regex characters are escaped, percent signs are protected, loops inside folders are blocked, and each rule is explained in plain words.

    4. Test, then paste

      Run a test URL through the rules to see every hop, then copy or download the code and paste it above the WordPress block.

    What this tool does, and what it doesn't

    A plain list, so you know exactly what to expect.

    This tool does

    • Build RewriteRule redirects for 5 common cases
    • Handle up to 500 page redirects at once
    • Redirect old URLs that have a ?query
    • Force HTTPS and www or non-www in one hop
    • Warn about loops and redirect chains
    • Test any URL against the rules

    This tool does not

    • Edit the .htaccess file on your server
    • Write Nginx or IIS configuration
    • Check that the new pages exist
    • See rules already on your server
    • Guarantee search rankings after a move
    • Send or store what you type

    Where your data goes

    Nowhere. The rules are built and tested by JavaScript in your browser, so the addresses you type are never sent to our server or to anyone else, and nothing is stored. Like any website, our server keeps normal access logs of page visits, as described in our privacy policy.

    Step-by-step guide by Bhavin J. Sheth.

    Read the .htaccess guide

    When a redirect does not work as expected

    The six problems people run into most, and how to fix each one.

    500 Internal Server Error after saving

    A typo, a missing mod_rewrite module, or rules pasted inside another block. Restore the backup, paste the code again as one block at the top, and ask your host whether mod_rewrite is on.

    Too many redirects

    Two rules send traffic back and forth, or the site is behind Cloudflare Flexible SSL. Tick the proxy option, and remove other HTTPS redirects in plugins or the hosting panel.

    The old URL still loads

    Your browser cached the old page or an earlier redirect. Test in a private window, clear the cache plugin and CDN, and check the rules are above # BEGIN WordPress.

    Two or three redirects in a row

    Older rules point to URLs that now redirect again. Point every old URL straight to its final address. The test panel shows each hop.

    A URL with ?id= does not redirect

    The Redirect directive cannot see query strings. Enter the old address with its query and this tool adds a RewriteCond for it.

    The rules do nothing at all

    The server may be Nginx, or Apache with .htaccess turned off (AllowOverride None). Ask your host, or add the redirect in the hosting panel instead.

    Questions about .htaccess redirects

    Where do I paste the generated code?

    Open the .htaccess file in your site's main folder (often public_html), using your host's file manager or FTP with hidden files shown. Download a backup first, then paste the rules at the very top, above the # BEGIN WordPress line, so they run before WordPress handles the request.

    Which status code should I choose?

    Use 301 for a page or site that has moved for good. Google treats 301 and 308 as permanent and 302 and 307 as temporary. 307 and 308 also make browsers repeat a form POST instead of switching to GET, which matters for forms and APIs, not for ordinary pages.

    Why do I get "too many redirects" after forcing HTTPS?

    Usually because the site sits behind Cloudflare with Flexible SSL or behind a load balancer. The visitor uses HTTPS, but the proxy talks to your server over plain HTTP, so the server keeps redirecting. Tick the Cloudflare or load balancer option, or switch Cloudflare to Full (strict) SSL, and turn off other HTTPS redirect plugins.

    I added the rule but the old page still loads. Why?

    Browsers cache 301 redirects and pages, so test in a private window. Check that the rules sit above the WordPress block, that a caching plugin or CDN cache has been cleared, and that your server actually reads .htaccess: Nginx does not, and some Apache hosts disable it.

    Does this work on Nginx, IIS or LiteSpeed?

    The code is for Apache with mod_rewrite, which most shared hosts use. LiteSpeed servers read the same rewrite rules from .htaccess. Nginx and IIS ignore .htaccess and need redirects written in their own configuration, so these rules will not work there.

    What happens to query strings like ?utm_source=?

    By default Apache keeps the query string and adds it to the new address, which keeps campaign tracking working. Tick Drop the query string to remove it. If the old address itself has a query, such as /page.php?id=5, the tool adds a condition so only that exact query is redirected.

    Is anything I type sent to your server?

    No. The rules are built and tested by JavaScript in your browser. No request is sent when you generate, test, copy or download, and nothing is stored. Like any website, our server keeps normal access logs of page visits, as described in our privacy policy.