SuperDevTools

Htaccess generator: 301 redirects, HTTPS, caching and security

Site address

www in the address
Trailing slash

Page redirects

Old address: a path such as /old-page or /product.php?id=12 (spaces and accents allowed). New address: a path or a full URL. Special characters are escaped for you.

    Move a whole domain

    Every page of the old domain, with or without www, is sent with a 301 to the same address on the new domain. Leave empty if you are not changing domain.

    Custom error pages

    Path of a page on your site, for example /404.html. Leave empty to keep the default error page.

    Caching and compression

    Security

    HSTS: once the header is received, the browser refuses any http:// access for the chosen time, and you cannot undo that from your side. Turn it on only when HTTPS works everywhere (and on every subdomain if you include them). Start with 5 minutes.

    Password-protect a folder

    Put a .htaccess file in the folder to protect with these four lines. AuthType Basic asks for a username and password, AuthName is the text shown in the prompt, AuthUserFile gives the absolute server path of the accounts file, and Require valid-user lets in any account from that file.

    AuthType Basic
    AuthName "Private area"
    AuthUserFile /absolute/path/outside/the/site/.htpasswd
    Require valid-user

    This generator does not create the .htpasswd file: the password must be hashed, which you do on the server with the htpasswd command or from your hosting control panel. Keep that file outside the public folder and always use HTTPS: with Basic authentication the password is only encoded, not encrypted.

    Your .htaccess file

    Things to check

      Everything happens in your browser: nothing is sent. Your settings stay on this device.

      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

      1. Under “Site address”, tick “Force HTTPS” and pick “Without www” or “With www”. Choose whether to remove or add the “Trailing slash”.
      2. 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”.
      3. Set the error pages, caching, compression and “Security” options.
      4. Read “Things to check”, then “Copy” or “Download”. The download is named htaccess.txt: rename it to .htaccess in 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} off
      • RewriteRule ^ 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.