My Tool Studio
SEO

.htaccess Generator

Moving a site to a new domain, or just to HTTPS, means writing Apache rules, and one wrong character can 500 the whole server. This htaccess redirect generator builds the file from checkboxes instead: force HTTPS, add or remove the www prefix, strip trailing slashes, and list custom 301s one per line. It works as a 301 redirect htaccess generator during migrations, where every old URL needs a permanent pointer to its new home, and as an htaccess rewrite generator for the host level rules that keep one URL format canonical. Everything is assembled in your browser, so you can use this htaccess generator online without an account and without your server config ever leaving the page.

Always freeNo sign upRuns in your browser

e.g. /old /new

# Generated by Toolora

<IfModule mod_rewrite.c>
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# Strip trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [L,R=301]

# Custom redirects
Redirect 301 /old-page /new-page
Redirect 301 /foo /bar
</IfModule>

# Enable Gzip
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

# Browser cache
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>

How to use

01

Set your domain and host rules

Type your domain into the Domain field, then tick the rules you need: Force HTTPS, Remove www or Force www, and Strip trailing slash. The output pane rebuilds with every change.

02

Add custom 301 redirects

In the redirects box, put one mapping per line as old path, space, new path, like /old-page /new-page. Each valid line becomes a Redirect 301 directive in the output.

03

Copy the finished .htaccess

Tick Gzip compression and Browser cache headers if you want the performance blocks, then press the copy button and paste the result into the .htaccess file at your site root.

Why .htaccess Generator

Common questions

What directives does the htaccess redirect generator write?
It writes RewriteCond and RewriteRule pairs inside an IfModule mod_rewrite.c block for the HTTPS, www, and trailing slash options, plus plain Redirect 301 lines for your custom mappings. The Gzip and cache options add mod_deflate and mod_expires blocks below that.
Can I force HTTPS and remove www in the same .htaccess file?
Yes, and it's the most common combination. The tool writes the HTTPS rule first and the www rule after it. They are separate rewrites, so a legacy http://www URL may take two hops; run the result through the Redirect Chain Checker if you want to see exactly how it resolves.
How do I format the custom redirects box?
One redirect per line: the source path, a space, then the destination, for example /summer-sale /sale. Lines missing either part are skipped silently, so double-check the output pane before you copy.
Does the generated .htaccess work on Nginx or IIS?
No. The file targets Apache and its mod_rewrite, mod_deflate, and mod_expires modules. Nginx uses return and rewrite directives in its own config syntax, and IIS uses web.config, so you'd translate the rules rather than copy them.
Why are the rules wrapped in IfModule mod_rewrite.c?
It's a safety guard. If mod_rewrite isn't compiled into your Apache build, the block is ignored instead of throwing a 500 error on every request. The site would run without redirects rather than not run at all.
Does the htaccess generator online output 301 or 302 redirects?
Every rule uses R=301 or Redirect 301, since permanent moves are what search engines should cache. For a temporary move, edit the copied text and change 301 to 302 on that specific line.
Where does the .htaccess file go on my server?
In the document root of your site, named exactly .htaccess with the leading dot and no extension. If a file already exists there, back it up first and merge the new rules in rather than overwriting settings your host placed there.

More SEO tools

View all