.htaccess Generator
Guide: How to Write a robots.txt File (With Examples)
Redirects
Works on Apache servers. Back up your old .htaccess first, because a mistake can take a site offline.
Nothing you enter or choose here leaves your device. This tool runs in your browser.
What the file is for
An .htaccess file sits in your site's folder and gives instructions to the Apache web server: send visitors to the secure address, redirect an old page, block an address, compress files. It's only for Apache. Nginx and many hosting control panels use a different format, so if your host isn't Apache, this file will do nothing.
A real example
Tick force HTTPS, remove www, block folder listings, hide dot files, compress text, add a 404 page and one redirect from /old-page to /new-page, and you get:
RewriteEngine On
# Send everything to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Never use www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]
# Redirects
Redirect 301 /old-page /new-page
ErrorDocument 404 /404.html
# Do not list folders
Options -Indexes
# Compress text files
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain ...
</IfModule>What each option does
| Option | Effect |
|---|---|
| Force HTTPS | Sends every http address to the https version with a permanent redirect |
| Add or remove www | Picks one version of your domain so search engines see a single site |
| Trailing slash | Makes addresses end with a slash, or never end with one |
| Redirects | Sends an old address to a new one, as 301 (permanent) or 302 (temporary) |
| Custom 404 page | Shows your own page instead of the server's plain one |
| Block folder listing | Stops visitors browsing a folder that has no index file |
| Hide dot files | Blocks access to files such as .env and .git |
| Block IP addresses | Refuses requests from addresses you list |
| Compression | Shrinks text files in transit so pages load faster |
| Browser caching | Tells browsers how long to keep images, styles and scripts |
Use 301 or 302?
A 301 says a page has moved for good, and search engines pass its standing to the new address. A 302 is temporary, and the old address stays the main one. For a permanent move, such as a renamed page, use 301. For a short-term detour, such as a sale page, use 302.
Test it safely
- Download your current .htaccess file and keep a copy. A mistake can take the whole site offline with a server error.
- Upload the new file to the root folder of your site.
- Load your home page and a few inner pages at once.
- Check redirects from the command line with
curl -I https://yourdomain.com/old-page, which shows the status code and the destination. - If you see a 500 error, restore the old file straight away and look for the line that caused it.
Mistakes that bite
- Redirect loops. Two rules that send visitors back and forth. If the browser says there are too many redirects, remove one rule.
- A chain of redirects. http to https and then non-www to www in separate hops slows pages. The rules above jump straight to the final address.
- Hosts that ignore the file. Some servers don't allow .htaccess to override settings. Ask your host.
- Forgetting the order. Rules are read from the top. Put specific redirects before general ones.
Nothing you type is uploaded. For search engine instructions, use the robots.txt generator and read the robots.txt guide. The HTTP status codes list explains 301, 302 and 404.
Written by Akinrinmade Michael · Updated October 24, 2026
How to use
- 1Tick the options you want.
- 2Add any redirects or blocked IP addresses.
- 3Copy the file into your site's root folder.
Frequently asked questions
Which servers does it work on?
Apache. Nginx and most hosting panels use a different format.
Is it safe to use?
Back up your old file first. A mistake in .htaccess can take a site offline.
What is the difference between 301 and 302?
301 is permanent and passes search ranking. 302 is temporary.
Can I force HTTPS?
Yes. Tick the first option.
Is my data uploaded?
No. Everything runs in your browser, so what you paste never leaves your device.
Read the guide
Learn how this works and how to get the most from it.
Web & SEO
How to Write a robots.txt File (With Examples)
What robots.txt does and doesn't do, how Disallow and Allow rules work, how to add your sitemap, and mistakes that can hide your whole site.
3 min read
Related tools
Robots.txt Generator
Build a robots.txt with rules for each crawler.
Meta Tag Generator
Generate SEO, Open Graph and Twitter Card meta tags with live previews.
HTTP Status Codes
Look up every HTTP status code, from 200 OK to 503 Service Unavailable.
URL Parser & Query Builder
Split a URL into its parts and edit its query parameters.