A correct .htaccess file without learning the syntax
A .htaccess file controls a .htaccess-compatible web server folder by folder: redirects, HTTPS, caching, error pages. One typo, though, can put a 500 error on every page. This htaccess generator writes the rules from checkboxes and fields, comments each block and puts everything in the right order. Nothing is uploaded: the file is built in your browser.
How to use it
- Under “Site address”, tick “Force HTTPS” and pick “Without www” or “With www”. Choose whether to remove or add the “Trailing slash”.
- Under “Page redirects”, fill in “Old address” and “New address”, choose “301 permanent” or “302 temporary”, and click “+ Add a redirect” for the next line. For a new domain name, use “Move a whole domain”.
- Set the error pages, caching, compression and “Security” options.
- Read “Things to check”, then “Copy” or “Download”. The download is named
htaccess.txt: rename it to.htaccessin the site root.
What each block does
The file opens with security: Options -Indexes stops folder listings, and a FilesMatch block refuses leftovers such as settings.php.bak or dump.sql. Then come the ErrorDocument lines and a single rewrite block with one RewriteEngine On. Order matters there: hidden files (.env, .git) refused, old domain, HTTPS, www, page redirects, trailing slash. Headers, caching (mod_expires) and compression (mod_deflate) sit inside <IfModule> blocks, so a missing module skips the block instead of breaking the site.
With “Force HTTPS” and “Without www” you get exactly:
RewriteCond %{HTTPS} offRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
A visit to http://www.example.com/pricing goes to https://www.example.com/pricing, then lands on https://example.com/pricing.
An htaccess redirect with a space and a query string
To send /old page?ref=7 to /new-page with a 301, the htaccess redirect generator writes RewriteCond %{QUERY_STRING} ^ref=7$ and then RewriteRule ^old\ page$ /new-page [R=301,QSD,L]. The rule itself never sees the query string, hence the RewriteCond line. The space is escaped with a backslash, the dot in .html becomes \., and QSD drops ?ref=7 from the target. When the old address has no query string, the visitor's parameters are passed on unchanged.
301 or 302 for SEO
A 301 says the page has moved for good: search engines replace the old URL with the new one and pass most of its ranking signals along. A 302 says the detour is temporary, for a page under repair or a seasonal sale, and the old URL stays indexed. Browsers remember a 301, sometimes for months, so test with a 302 in a private window and switch to 301 once it works. Point each old page at its real equivalent, not everything at the home page, and avoid redirect chains.
FAQ
Why does my site show a 500 error after uploading the file?
Your host does not allow one of the directives, or a module is missing. Put the old file back, then remove blocks one at a time; Options -Indexes is the line most often refused.
Should I turn on HSTS?
Only once the whole site works over HTTPS. After the header is received, the browser refuses http:// for the chosen time. Start with “5 minutes (trial)”.
How do I password-protect a folder?
Open “Password-protect a folder”: the four directives are explained there. The .htpasswd file is created on the server with a hashed password, not on this page.
Are my settings saved?
Yes, on this device only. “Default settings” resets the form.