Quick answer
To create .htaccess redirects, choose what you want to redirect — one page to another, many pages from a list, a folder, a whole old domain to a new domain, force HTTPS, force or remove www, remove .html/.php extensions or remove trailing slashes — fill in the paths or domains and pick the redirect type (301, 302, 307 or 308). Copy the generated rules and paste them at the top of the .htaccess file in your site's root folder.
- Redirects:
- Page to page, bulk list, folder, whole domain
- Clean-ups:
- Force HTTPS, force www, remove www
- URL tidy:
- Remove .html/.php, remove trailing slash
- Types:
- 301, 302, 307, 308
- Servers:
- Apache and LiteSpeed (most shared hosting)
- Output:
- Copy-ready .htaccess rules
- Account:
- Not required
- Price:
- Free
Redirects are part of every website's life. You rename a page, merge two posts, reorganise categories, switch from HTTP to HTTPS, choose www or non-www, or move to a completely new domain. Each time, old URLs must forward visitors and search engines to the new ones — otherwise people land on 404 errors and you lose the rankings and links those pages earned.
On Apache and LiteSpeed servers, which power most shared hosting including Hostinger, cPanel hosts and many WordPress sites, redirects live in a file called .htaccess. Its syntax — Redirect, RewriteEngine, RewriteCond, RewriteRule with regular expressions and flags — is powerful but unforgiving. One wrong character can break the whole site with a 500 error or create a redirect loop.
Our .htaccess redirect generator writes the rules for you. Choose a scenario, fill in a few fields and the correct code appears, using the right redirect status and safe patterns. For bulk moves, paste a list of old paths and new URLs and get one rule per line. Copy the code, paste it into your .htaccess file and test.
How to create .htaccess redirects – step by step
- 1 Choose the scenarioPick one page, many pages, a folder, a whole domain, force HTTPS, force/remove www, remove extensions or remove trailing slashes.
- 2 Fill in the detailsEnter old paths, new URLs, folders or domains as asked. For bulk redirects, enter one "old-path new-url" pair per line.
- 3 Choose the redirect typeUse 301 for permanent moves (best for SEO); 302 or 307 only for temporary changes.
- 4 Back up and pasteDownload a copy of your current .htaccess first, then paste the new rules near the top of the file in your site's root folder.
- 5 TestOpen the old URLs in a private window and check them with the Redirect Checker; make sure there are no loops.
Why use this .htaccess redirect generator?
Nine common scenarios
Covers almost every redirect a typical site needs.
Correct status codes
301, 302, 307 or 308 as you choose.
Bulk redirects
Turn a list of URLs into rules in seconds.
Safe patterns
Conditions prevent loops for HTTPS and www rules.
No syntax to learn
Simple fields instead of regular expressions.
Free and instant
Copy-ready code, no sign-up.
Which redirect type should you use?
| Code | Meaning | Use for |
|---|---|---|
| 301 | Permanent | Renamed or moved pages, domain changes, HTTPS and www — the standard SEO choice |
| 308 | Permanent, keeps method | Permanent moves of forms or API endpoints |
| 302 | Temporary | Short-term promotions, maintenance, testing |
| 307 | Temporary, keeps method | Temporary moves of forms or API endpoints |
Where is the .htaccess file?
The file sits in your website's root folder — usually public_html on shared hosting. Because its name starts with a dot, it is hidden by default: in cPanel's or hPanel's File Manager, enable "Show hidden files". If no file exists, create a new plain text file named exactly .htaccess. WordPress sites already have one containing the WordPress block between # BEGIN WordPress and # END WordPress; place your redirects above that block and never edit inside it, because WordPress may overwrite it.
Moving to a new domain
When you change domain, keep the old domain registered and hosted, and redirect every URL to the same path on the new domain with a 301 — not everything to the new home page. The "whole old domain → new domain" option does this in one rule, preserving paths and query strings. Then use Google Search Console's Change of Address tool, update your sitemap (build one with the Sitemap Generator), update links on social profiles and directories, and keep the redirects active for at least a year — ideally permanently.
Forcing HTTPS and choosing www or non-www
Once your SSL certificate works (check it with the SSL Checker), redirect all HTTP traffic to HTTPS and choose one host version — www or non-www — redirecting the other to it. Combining the rules correctly gives every visitor a single hop to the preferred URL. If your site is behind Cloudflare with "Flexible" SSL, HTTPS redirect rules on the server can cause loops; switch Cloudflare to "Full (strict)" or use Cloudflare's own "Always Use HTTPS" setting instead.
Bulk redirects after a redesign
Redesigns and CMS migrations often change many URLs at once. Build a redirect map: export your old URLs (from your old sitemap, Search Console or analytics), match each one to its best new equivalent, and paste the pairs into the "Many pages" option. Prioritise pages with traffic and backlinks. Redirect removed content to the closest relevant page — not everything to the home page, which Google may treat as a soft 404. Remove duplicate lines from your list first with Remove Duplicate Lines.
Clean URLs: removing extensions and trailing slashes
Removing .html or .php from URLs makes them shorter, cleaner and independent of the technology behind them. The generator creates rules that redirect the extension version to the clean URL and internally serve the right file. Similarly, choose one trailing-slash style and redirect the other, so search engines do not see two versions of every page. Apply these only to sites built with static files or plain PHP — CMS platforms like WordPress manage URLs themselves.
Testing and troubleshooting safely
Always keep a backup of the original .htaccess before editing; if the site shows a 500 Internal Server Error after saving, restore the backup immediately — it usually means a syntax error or a module not enabled on your server. Test redirects in a private window, because browsers cache 301s aggressively. Trace each old URL with the Redirect Checker to confirm a single hop and a final 200 status, and look at response headers with the HTTP Headers Checker.
A redirect checklist for site owners
Before you touch .htaccess, write down every change you plan: which URLs move, where they go and why. Download a backup of the current file and keep it somewhere safe. Add the new rules in one block at the top with a comment line describing them and the date, so you or a developer can understand them later. Save, then immediately open the home page and a few inner pages to confirm the site still loads. Test each redirected URL in a private window and with the Redirect Checker. Update internal links in menus, content and footers to point directly at the new URLs, so visitors and search engines do not need the redirect at all. Finally, watch Google Search Console's Pages report over the following weeks for new 404 errors or redirect problems, and fix any you missed.
What about nginx and other servers?
.htaccess files work only on Apache and LiteSpeed. If your site runs on nginx, redirects go in the server configuration using return 301 or rewrite directives, which require server access. Managed platforms — Shopify, Wix, Squarespace, Webflow — have their own URL redirect settings in the dashboard. WordPress users can also manage redirects with plugins such as Redirection or Rank Math's redirection module.
Troubleshooting
- 500 Internal Server Error. Restore your backup; check for typos and that mod_rewrite is enabled.
- Too many redirects. HTTPS or www rules conflict with your CMS, CDN or another rule. Keep only one place in charge.
- Redirect not working. Rules may be placed after the WordPress block or another rule that matches first; move them to the top.
- Old redirect still happens. Your browser cached the 301; test in a private window.
Frequently asked questions
What is an .htaccess redirect?
A rule in Apache's .htaccess file that sends visitors from one URL to another.
Where do I put the redirect code?
At the top of the .htaccess file in your site's root folder, above the WordPress block.
Should I use 301 or 302?
Use 301 for permanent changes; 302 only when the old URL will return.
How do I force HTTPS with .htaccess?
Choose Force HTTPS, copy the rules and paste them at the top of .htaccess.
How do I redirect a whole domain?
Choose Whole old domain → new domain to redirect every path to the same path on the new domain.
Does .htaccess work on nginx?
No. nginx uses server configuration instead.
Why did my site show a 500 error?
There is a syntax error or a missing module. Restore your backup and check the rules.
Can I redirect many URLs at once?
Yes. Use Many pages and enter one old path and new URL per line.
Do redirects hurt SEO?
Correct 301 redirects preserve most ranking signals; long chains and wrong redirects can hurt.
Is the generator free?
Yes. No sign-up required.
How long should I keep redirects?
At least a year, ideally permanently.
Last updated November 21, 2026 · Written and tested by the SmallEasyTools team.