htaccess Redirect Generator

Turn a list of old and new URLs into correct Apache rewrite rules, with HTTPS, www and domain moves handled in a single hop.

Runs entirely in your browser. Nothing you add is sent to us.

Create a free account to use the htaccess Redirect Generator

Free forever for this tool. Takes a few seconds — then you come straight back here.

  • All 150 free tools, one login
  • Free website audit with fixes
  • Search Console dashboard
  • Free keyword rank tracker

Already have an account? Sign in

htaccess Redirect Generator — htaccess redirect generator

An htaccess redirect generator writes Apache rewrite rules for you, so you do not have to remember mod_rewrite syntax or worry about escaping the wrong character. Our free tool creates single 301 and 302 redirects, bulk redirects from a two-column list of old and new URLs, force HTTPS, www to non-www or the reverse, trailing slash rules and a whole-domain move that keeps every path. It escapes regex characters correctly, warns about redirect chains, loops and duplicates, and lets you copy or download the result. Everything runs in your browser.

How to use the htaccess redirects

  1. 1 Choose your site-wide rulesTick force HTTPS, pick a www preference and decide whether URLs should end with a slash. For a rebrand, switch on move to a new domain instead.
  2. 2 Enter your domainAdd your domain so each page redirect points straight at the final https address, avoiding a two-step chain.
  3. 3 Add page redirectsType one old and new URL pair, or paste a two-column list from a spreadsheet. Paths and full URLs both work, including old URLs with query strings.
  4. 4 Fix any warningsRead the warnings for loops, chains, duplicates and invalid lines, and correct the list until they disappear.
  5. 5 Copy, upload and testCopy or download the rules, paste them at the top of your .htaccess file, then check each old URL with our Redirect Checker.

What .htaccess redirects are and when to use them

The .htaccess file is a configuration file that Apache web servers read from your site's folders on every request. Most UK shared hosting, including cPanel and Plesk accounts, runs Apache or LiteSpeed, which understands the same rules. Adding redirects there lets you send visitors and search engines from an old address to a new one without touching your website's code.

You need redirects whenever a URL changes: when you rename a page, restructure a menu, move from .html or .php file names to clean URLs, merge two pages, switch to HTTPS, or move to a new domain. Without them, old links in emails, social posts, bookmarks and search results lead to a 404 error, and the search ranking that the old page had built up is lost.

If your site runs on Nginx, a managed platform such as Shopify, Wix or Squarespace, or behind a host that does not allow .htaccess, these rules will not work. Those platforms have their own redirect settings. WordPress sites on Apache can use .htaccess, but the rules must go above the BEGIN WordPress block so WordPress does not handle the request first.

301 or 302: choosing the right status code

A 301 redirect tells browsers and search engines that a page has moved permanently. Google transfers ranking signals to the new URL and, over time, replaces the old address in its results. Use 301 for almost every site change: renamed pages, a new URL structure, HTTPS, www changes and domain moves.

A 302 redirect means the move is temporary and the old URL will return. Use it for short campaigns, seasonal pages, maintenance pages and A/B tests. Search engines keep the original URL in their index while a 302 is in place, although Google may treat a long-running 302 as permanent.

Browsers cache 301 redirects aggressively, sometimes for months, so a mistake can be hard to undo for visitors who have already followed it. A sensible habit is to deploy new rules as 302, test them, and switch to 301 once you are sure. The generator lets you toggle between the two with one click.

Bulk redirects, regex escaping and query strings

For a site migration you may have dozens or hundreds of old URLs. Export them from your old sitemap, analytics or Search Console into a spreadsheet, put the new address next to each, and paste the two columns into the bulk box. Spaces, tabs, commas and arrows all work as separators, and lines starting with a hash are treated as comments.

Each line becomes a RewriteRule. The old path is a regular expression, so characters such as dots, question marks, brackets and plus signs have special meanings and must be escaped with a backslash. The generator escapes them for you: /about-us.php becomes ^about-us\.php/?$, which matches only that exact path, with or without a trailing slash if you leave that option on. The rules are anchored with ^ and $ so /blog does not accidentally catch /blog/my-post.

Query strings need special handling because RewriteRule only sees the path. If an old URL includes something like ?product=12, the generator adds a RewriteCond that checks the query string and uses the QSD flag so the old parameters are not carried over to the new page. Percent signs in new URLs are escaped and the NE flag is added, so encoded characters such as %20 arrive intact.

Force HTTPS, www and trailing slashes without chains

Every site should load on one canonical address, such as https://yoursite.co.uk, with the other versions redirecting to it. A common mistake is writing separate rules for HTTPS and for www, which sends a visitor to http://www.yoursite.co.uk through two redirects: first to https://www, then to https without www. Each extra hop adds delay and can dilute signals.

The generator combines HTTPS and www handling into a single rule, so any wrong combination goes straight to the right address in one hop. If your site sits behind Cloudflare, a load balancer or a proxy that handles HTTPS for you, tick the option for it. The server then checks the X-Forwarded-Proto header rather than its own HTTPS status, which avoids an endless redirect loop.

  • Remove trailing slash: /services/ redirects to /services, while real folders are left alone so directory indexes still work.
  • Add trailing slash: /services redirects to /services/, while files with extensions such as .css, .js and .jpg are skipped.
  • Pick one style and match your internal links, canonical tags and sitemap to it, so search engines see one version of each page.

Moving to a new domain

When you rebrand or move to a new domain, every old URL should redirect to the same path on the new domain, so /contact on the old site goes to /contact on the new one. The domain move option writes one rule that does exactly that, keeping paths and query strings. Specific page redirects are placed above it and automatically point to the new domain, so pages whose address also changed go straight to their final home.

Keep the old domain registered and the redirects live for at least a year, and ideally for good, because links from other websites keep sending visitors and value for a long time. In Google Search Console, verify both domains and use the change of address tool. Update your Google Business Profile, social profiles, email signatures and directory listings too, so fewer people rely on the redirect in the first place.

Testing redirects and avoiding loops

The generator checks your list before you upload it. It warns when an old URL redirects to itself, which causes a loop and a too many redirects error in the browser, when two lines redirect the same old URL, because only the first one will run, and when a new URL is itself redirected by another line, creating a chain. Fix chains by pointing every old URL straight at its final destination.

Back up your current .htaccess before making changes, because a single typo can stop the whole site loading with a 500 error. Upload the new rules, then test a sample of old URLs, including ones with and without trailing slashes, upper case letters and query strings. Our Redirect Checker shows every hop and status code, so you can confirm each one returns a single 301 to the right place. Finally, update internal links so your own pages link directly to the new addresses rather than through redirects.

Examples you can copy

Single page redirect

RewriteEngine On
RewriteRule ^old-page/?$ https://yoursite.co.uk/new-page [R=301,L]

Force HTTPS and remove www in one hop

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+?)\.?$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]

Old URL with a query string

RewriteCond %{QUERY_STRING} ^product=12$
RewriteRule ^shop/?$ https://yoursite.co.uk/products/oak-table [R=301,L,QSD]

Move a whole domain, keeping paths

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?old-name\.co\.uk\.?$ [NC]
RewriteRule ^ https://newname.co.uk%{REQUEST_URI} [R=301,L,NE]

Common mistakes to avoid

Placing rules below the WordPress block

WordPress catches the request first, so your redirects never run. Put them at the top of .htaccess.

Separate HTTPS and www rules

Two rules create a two-hop chain for some visitors. Combine them into one rule.

Not escaping dots and question marks

An unescaped dot matches any character and a question mark makes the previous character optional, so rules catch the wrong URLs.

Redirecting everything to the home page

Google treats mass redirects to the home page as soft 404s. Map each old page to its closest equivalent.

Mixing Redirect and RewriteRule

mod_alias and mod_rewrite run separately and in an order you may not expect. Stick to RewriteRule throughout one file.

Frequently asked questions

They work on Apache and LiteSpeed servers that allow .htaccess files, which includes most cPanel and Plesk hosting. Nginx and hosted platforms such as Shopify or Wix use their own redirect settings.

After uploading, test a few old URLs with our free Redirect Checker. Each should show a single 301 straight to the new address.

It sits in your site's document root, often public_html on cPanel hosting. It starts with a dot, so turn on show hidden files in your file manager or FTP client.

No. Nginx ignores .htaccess files and uses return or rewrite directives in its own configuration. LiteSpeed servers do read .htaccess.

At least a year, and ideally permanently, because old links and bookmarks keep sending visitors long after search engines have updated.

Usually a rule redirects a URL to itself or two rules send visitors back and forth. Sites behind Cloudflare also loop if HTTPS is checked the wrong way.

Short chains still work, but each hop slows the page and Google stops following after several. Point every old URL straight at its final address.

Yes. Put the full https address of the other site in the new URL column and the rule will send that page there.

No. The rules are generated in your browser and nothing is uploaded, so you can safely paste a full list of URLs from an unreleased site.

Learn more

Free website audit

See how your site scores, free

Speed, SEO, DNS, email (SPF/DKIM/DMARC) and security in one scan, with a prioritised fix list.