Used for absolute redirect targets and the domain move
Used by every rule. Add 301 or 302 after a page redirect to override it.
Path to your error page, e.g. /404.html
One per line: subdomain then folder, e.g. blog /blog/. The subdomain must point at this server.
One per line or comma separated; ranges like 203.0.113.0/24 work
Every path on your domain is sent to the same path on the new one
Paste two columns from a spreadsheet, or type /old /new. Full URLs are reduced to their path and query.
2 page redirects. The download is named htaccess.txt; rename it to .htaccess on the server.
# Generated by MyToolStudio (Apache .htaccess)
<IfModule mod_rewrite.c>
RewriteEngine On
# Page redirects (listed first so each old URL takes one hop)
RewriteRule ^old-page/?$ https://example.com/new-page [R=301,L]
RewriteCond %{QUERY_STRING} ^id=12$
RewriteRule ^shop/?$ https://example.com/products/blue-mug [R=301,L,QSD]
# Force HTTPS and remove www in one hop
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
</IfModule>How to use
Set your domain and site-wide rules
Type your domain, pick 301 or 302 under Redirect type, and tick Force HTTPS, Remove www or Force www, Strip trailing slash and Force lowercase URLs as needed. Choose an extension to remove, and fill in a new domain only if the whole site is moving.
Paste page redirects and extras
Put one redirect per line: old URL, new URL, then 301 or 302 to override the default. Tabs, commas or spaces all work. Add a custom 404 path or IP addresses to block if you need them.
Copy the Apache or Nginx code
Keep the Apache .htaccess tab for Apache and LiteSpeed, or open Nginx for an Nginx server. Press Copy or Download, back up your current config, then add the new rules near the top.
Why Htaccess Redirect Generator
- Force HTTPS and the www choice happen in one redirect, not two.
- Bulk page redirects from full URLs, with query strings matched exactly.
- Lowercase, extension removal, custom 404 and IP blocking rules without hand-written regex.
- The same setup as Apache .htaccess or as Nginx server blocks.
Common .htaccess redirect rules
These are the rules the generator writes, shown on their own so you can see what each part does. In .htaccess, the pattern in a RewriteRule is matched against the path without its leading slash, which is why a page rule starts with ^old-page and not ^/old-page. %1 in a target reuses the part captured by the last RewriteCond, and $1 reuses the part captured by the RewriteRule pattern itself. Swap example.com, old.com and new.com for your own domains.
| Goal | RewriteCond | RewriteRule |
|---|---|---|
| HTTP to HTTPS | %{HTTPS} off | ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
| Remove www | %{HTTP_HOST} ^www\.(.+)$ [NC] | ^ https://%1%{REQUEST_URI} [L,R=301] |
| Add www | %{HTTP_HOST} !^www\. [NC] | ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
| Strip trailing slash | %{REQUEST_FILENAME} !-d | ^(.+)/$ /$1 [L,R=301] |
| Move to a new domain | %{HTTP_HOST} ^(www\.)?old\.com$ [NC] | ^(.*)$ https://new.com/$1 [L,R=301] |
| One page to another | None needed | ^old-page/?$ https://example.com/new-page [R=301,L] |
Mistakes that break .htaccess redirects
Most redirect problems come from a handful of habits. Check the list below before you upload a new file, and test a few old URLs with the Redirect Checker afterwards to confirm each one lands in a single hop.
- Chaining rules so an old URL goes to HTTPS, then to www, then to the new page. Each extra hop slows the page and wastes crawl budget.
- Sending every old page to the home page. Google tends to treat that like a missing page, so send each URL to its closest match.
- Using 302 for a permanent move, which can keep the old URL in search results for longer.
- Pasting new rules below a WordPress or CMS block that already rewrites every request, so your rules never run.
- Editing the live file without a backup. One typo can return a 500 error for the whole site.
- Forcing HTTPS behind a proxy that talks to your server over HTTP, which causes a redirect loop.