About this .htaccess generator
On Apache web servers, a .htaccess file in your site’s root folder can redirect old URLs, force HTTPS, and change how files are served without touching the main server configuration. Getting the rewrite syntax right is fiddly, and a mistake can take a site offline. This generator writes the common rules for you, each with a comment explaining it: single-page, folder, and regular-expression redirects with the status code you choose, HTTPS and www normalization, HSTS, IP blocking or allow-listing, country blocking, trailing slashes, extension-free URLs, hotlink protection, browser caching, and GZIP compression. Rules are wrapped in IfModule checks where possible, so a missing module is skipped instead of causing an error.
How to create .htaccess redirects
- Add your redirects. Enter each old URL and its new address, choose the type and status code, or press a preset to start.
- Pick the site-wide options. Set HTTPS and www, clean URLs, a 404 page, security, and speed options. Enter your domain where needed.
- Generate and install. Press Generate .htaccess, copy or download the rules, back up your current file, and upload the new one to your site’s root folder. Test a few URLs afterwards.
Frequently asked questions
Should I use a 301 or a 302 redirect?
Use 301 when a page has moved for good, which tells search engines to pass its ranking to the new URL. Use 302 or 307 for temporary moves, such as maintenance pages, when the old URL will come back.
Where do I put the .htaccess file?
Upload it to the root folder of your website, usually public_html or www, next to your homepage. The file name starts with a dot, so turn on hidden files in your FTP program to see it.
Does .htaccess work on Nginx?
No. .htaccess files are an Apache and LiteSpeed feature. Nginx ignores them, so the same redirects must be written in the Nginx server configuration instead.
My site shows a 500 error after uploading. What now?
Restore your backup first. A 500 error usually means the server does not allow a directive or a module is missing; remove sections one at a time to find which one, and ask your host which modules are enabled.
What is HSTS?
HTTP Strict Transport Security tells browsers to always use HTTPS for your site for a set time. Only turn it on once HTTPS works everywhere on your domain, because browsers will refuse plain HTTP afterwards.