Htaccess Redirect
Free .htaccess redirect generator that produces correct Apache RewriteRule syntax for 301 redirects, www-to-non-www, HTTPS forcing, and trailing slash handling. Drop the output directly into your .htaccess file and your redirects work — no syntax errors, no broken regex.
Share on Social Media:
Htaccess Redirect Generator: Build Working Apache Redirects in Seconds
One missing flag in a RewriteRule can take an entire site offline with a "too many redirects" loop, and one wrong status code can quietly drain months of search rankings. The Htaccess Redirect tool from Tools Hub exists to stop those two failures before they reach your server. You describe the move in plain terms — old page to new page, force HTTPS, swap domains, strip the www — and it hands you a clean, loop-safe block of .htaccess code with the correct directive, the right RewriteCond guard, and a 301 already selected. No memorizing mod_rewrite syntax, no copy-pasting a forum snippet that was written for someone else's directory layout.
It is a free htaccess redirect generator that runs entirely in your browser. The URLs you type and the rules it builds never leave your device, so you can safely paste staging hostnames or unpublished paths into it. There is no sign-up, no usage cap, and the output carries no watermark or tracking comment — what you copy is byte-for-byte what runs on Apache.
How to Create an Htaccess Redirect
You never touch raw configuration until the code is finished and copyable. The workflow is short:
- Choose your redirect type. Single URL to a new URL, an entire domain to another domain, HTTP to HTTPS, www to non-www (or the reverse), everything to the homepage, or a custom wildcard pattern. Each type loads the correct directive style behind the scenes.
- Enter the source URL or path. Type the address you are moving away from — a relative path like
/old-page.htmlor a full host likeold-domain.com. The tool normalizes either format. - Enter the destination. Provide where visitors should land, such as
/new-page.htmlorhttps://new-domain.com. For domain moves it can keep the rest of the path so deep links survive. - Select the status code. 301 for a permanent move (the default, and the right call for SEO) or 302 for a genuinely temporary one.
- Toggle extra options. Preserve query strings, match case-insensitively, or add a trailing-slash rule — flags applied for you instead of typed by hand.
- Generate and copy. The tool outputs a tidy block including
RewriteEngine Onwhere it is needed. Use the one-click copy, paste it near the top of your root .htaccess, save, and test in a private window.
Build one rule and leave, or stack several in a single session and paste the whole set at once.
The .htaccess File: What You Are Actually Editing
The .htaccess file (the leading dot makes it hidden on Unix systems) is a per-directory configuration file that Apache reads on every request. When a request arrives, Apache walks up from the requested folder applying any .htaccess directives it finds before serving the page. Because it is read live and per-directory, you can change server behavior — redirects included — without editing the main config or restarting Apache. That convenience is also the trap: a syntax error in this file is applied instantly to every visitor, with no restart needed to break things.
The two ways Apache writes a redirect
Most of the confusion behind searches like htaccess not redirecting properly comes from mixing up two different modules:
mod_alias — the Redirect and RedirectMatch directives. The simplest form. A single line such as Redirect 301 /old-page.html https://example.com/new-page.html sends a permanent redirect. RedirectMatch adds regular-expression matching. This style is readable and ideal for plain one-to-one moves.
mod_rewrite — the RewriteRule directive. The engine behind anything conditional: forcing HTTPS, wildcards, query-string handling, and rules gated by RewriteCond. The generator picks whichever module fits your scenario, so you never have to decide which one to invoke or worry about loading the wrong one.
301 versus 302: the code that decides your rankings
A 301 ("Moved Permanently") tells search engines the old URL is gone for good and that ranking signals should flow to the new URL — what you want for nearly every migration. A 302 ("Found / temporary") keeps the old URL indexed because you have signaled the change is short-lived; reserve it for A/B tests or seasonal promotions. Choosing 302 by accident is a quiet, common cause of lost traffic, which is why this generator defaults to 301 and makes you opt into 302 on purpose.
Worked Examples: Real Input and the Exact Output
Here is what the generator actually produces for the four most-requested scenarios, with the inputs that drive each one.
Single page to a new page
Input: source /services/seo.html, destination /seo-services/, status 301. Output:
Redirect 301 /services/seo.html https://example.com/seo-services/
Because the match is exact, every other page on the site is untouched. A request to /services/seo-pricing.html would not be affected by this rule.
Force the whole site to HTTPS
Input: redirect type "HTTP to HTTPS". Output:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
The RewriteCond %{HTTPS} off line is the part people leave out by hand — without it, the rule keeps firing on its own secure output and the browser reports "too many redirects". The [R=301,L] flags mean "permanent redirect, last rule". A visitor hitting http://example.com/blog/post lands on https://example.com/blog/post with the path intact.
Move to a new domain and keep the path
Input: source old-domain.com, destination https://new-domain.com, path preservation on. Output:
RewriteEngine On
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
Here the $1 captures everything after the host, so old-domain.com/blog/2024/launch forwards to new-domain.com/blog/2024/launch — not to a bare homepage. That single difference is what keeps inbound backlinks pointing at real content instead of dumping every link's value onto your front page.
Strip www so you have one canonical host
Input: redirect type "www to non-www". Output:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Search engines treat www.example.com and example.com as two separate sites until you pick one. The %1 back-reference reuses the captured non-www host from the condition, and [NC] makes the match case-insensitive so WWW. is caught too.
Where Redirects Earn Their Keep
Hand-writing rewrite rules looks trivial until a stray slash silently breaks the site. These are the situations where generating the block instead pays off:
- Migrations and redesigns. Changing CMS, theme, or URL structure can break hundreds of links overnight. Generate a batch of htaccess 301 redirect rules so every legacy URL points at its new home and rankings transfer cleanly.
- Moving to a new domain. Rebranding or merging? The htaccess 301 redirect to new domain option forwards every visitor and backlink to the new host with the deep path preserved.
- Forcing HTTPS after installing SSL. The http to https redirect htaccess preset writes the secure rule with the loop guard already in place.
- Standardizing www vs non-www. One generated rule consolidates the two versions into a single canonical host.
- Retiring product or blog pages. Discontinued an item or merged two articles? Point the old URL at the closest relevant page instead of a 404.
- Sunsetting a microsite. The htaccess redirect all pages to homepage option sweeps a temporary or retired section to
/. - Cleaning up index files. Strip
index.phporindex.htmlso the homepage has one clean canonical URL — the case behind redirect index.php to root htaccess.
Edge Cases Worth Knowing Before You Paste
Most redirect headaches come from a handful of repeating traps. The generator handles these, but knowing why they exist saves you when you inherit someone else's file.
- WordPress overwrites its own block. Anything between
# BEGIN WordPressand# END WordPresscan be rewritten when permalinks are saved. Put your redirects above that block or they will vanish on the next update. - Combining HTTPS and domain changes bounces visitors twice. If you force HTTPS in one rule and change domains in another, a visitor can hit two consecutive 301s. Merge them into a single rule that goes straight to the final
https://new-domain.com/...address. - Redirect chains dilute SEO. A → B → C wastes a round-trip and leaks ranking signal at each hop. Point every old URL directly at its final destination, even if that means updating an older rule.
- Exact match vs. prefix.
Redirect 301 /blog(mod_alias) actually matches/blogand everything under it —/blog-oldincluded — because it is a prefix match. When you need a true one-to-one move, the generator uses a pattern that anchors the match so neighboring paths are not swept up by accident. - Trailing slashes are not cosmetic.
/pageand/page/are distinct URLs to Apache. If both are linked externally, decide on one and redirect the other, or you split your ranking signal between two addresses. - Query strings need an explicit flag. By default a rewrite may append or drop the original query string depending on the pattern. Enable the preserve-query option when the destination needs
?utm_source=...or pagination parameters carried over.
Deploying the Code Reliably
A few habits separate redirects that just work from ones that generate support tickets:
- Place redirect rules near the top of the file. Apache reads top to bottom; put redirects before caching, compression, or WordPress rewrite blocks so they fire first.
- Back up before you paste. Copy the current .htaccess to
.htaccess.bakfirst. If anything misbehaves you restore in seconds. - Test in a private window. Browsers cache 301s hard. Use incognito or a different device when verifying so a cached result does not fool you.
- Save the filename exactly. It must be literally
.htaccess— no name before the dot, no.txtextension that some editors silently append. - Commit to 301 only when you are sure. Because browsers cache permanent redirects, a mistaken 301 is hard to reverse for visitors who already cached it.
Tips & Troubleshooting
Why is my htaccess redirect not working at all?
The usual culprit is AllowOverride None on the server, which makes Apache ignore .htaccess files entirely — confirm with your host that overrides are enabled. The next most common cause is a misnamed file: it must be exactly .htaccess with the leading dot and no extension. If your rule uses RewriteRule, also confirm mod_rewrite is loaded.
Why do I get a "too many redirects" loop error?
This happens when an HTTPS or www rule lacks the condition that stops it firing on its own output. The code this tool generates includes the necessary RewriteCond guards. If you wrote the rule by hand, regenerate it here and replace the old block.
My redirect works but drops the path or query string. How do I fix it?
Enable the preserve-path and preserve-query options before generating. For domain moves, path preservation maps the full original URL onto the new host; without it, every request lands on the bare homepage, which hurts users and SEO alike.
Should I put the redirect above or below my WordPress rules?
Above the # BEGIN WordPress block. WordPress controls everything between its BEGIN and END markers and may rewrite that section, so rules placed inside it can be lost during updates. Keeping yours above the block protects them and gives them priority.
Will a 301 redirect hurt my Google rankings?
No — done correctly, a 301 passes the large majority of ranking signals to the new URL and is the recommended way to move content. Problems come only from chains, loops, or an accidental 302. Stick to direct 301s and rankings transfer smoothly.
The redirect appears cached and I cannot test changes. What now?
Browsers cache 301 responses aggressively. Test in a fresh incognito window, clear your browser cache, or use an online HTTP header checker that does not cache. On your own machine you can append a throwaway query string to force a fresh request.
Will these rules work on Nginx or only Apache?
The .htaccess format is specific to Apache (and Apache-compatible servers like LiteSpeed). Nginx uses a different configuration syntax and does not read .htaccess files, so these rules target Apache-based hosting — which covers the majority of shared and managed WordPress plans.
Related Tools
Tools Hub offers a full suite of free web utilities that pair naturally with redirects. If you manage a site, these are worth bookmarking:
- Robots.txt Generator — create a clean crawler-control file to sit alongside your redirect rules and guide search engines.
- HTML Minifier — shrink page markup for faster loads once your new URLs are live.
- URL Encoder / Decoder — safely encode special characters in destination URLs before pasting them into a rule.
- Meta Tag Generator — build canonical and SEO meta tags that reinforce the canonical URLs your redirects establish.
- QR Code Generator — turn your new canonical URLs into scannable codes for print and packaging.
- Password Generator — create strong credentials for the FTP and control-panel accounts you use to upload the edited file.
Frequently Asked Questions
Is the Htaccess Redirect tool really free?
Yes. The generator is completely free with no hidden tiers, no usage caps, and no credit card. Build as many redirect rules as you need, as often as you like.
Do I need to create an account or sign up?
No. There is no sign-up, no login, and no email required. Open the page and start generating .htaccess code immediately.
Does the generated code contain any watermark or branding?
No. The output is clean, standard Apache configuration with no comments advertising the tool, no hidden tracking, and no watermark. What you copy is exactly what runs on your server.
Are my URLs uploaded anywhere?
No. Everything happens locally in your browser, so the source and destination URLs you enter never leave your device. That makes the tool safe for internal, staging, or confidential addresses, and it keeps working even if you go offline after the page loads.
Can this tool redirect to another domain and keep the full path?
Yes. Choose the domain-redirect option and enable path preservation. A request to old.com/blog/post then forwards to new.com/blog/post instead of dropping the visitor on the homepage, which protects backlinks and user experience.
Can I force HTTP to HTTPS with this generator?
Absolutely. The http to https redirect htaccess preset writes the secure-redirect rule with the loop-prevention condition included, so once your SSL certificate is installed every visitor is sent to the encrypted version of your site.
Does it support wildcard and folder-wide redirects?
Yes. Use the wildcard or folder option to map an entire directory to a new location in a single rule, so you do not have to enumerate every file. This covers the common htaccess redirect wildcard and folder-migration cases.
What is the difference between 301 and 302, and which should I choose?
A 301 is a permanent redirect that passes SEO value to the new URL and is right for almost all moves. A 302 is temporary and keeps the old URL indexed; use it only for short-lived changes like tests or promotions. The tool defaults to 301 so you get the SEO-safe option automatically.
🔗 Relevant Tools
Link to this tool
Found this tool useful? Add it to your website or blog with one of these snippets.
Add the live, working tool to your own page:
Leave a comment
Comments go straight to our team — they are not published on the site.