.htaccess Generator

Redirects
Caching
Security

Generated .htaccess Code

Using the .htaccess Generator

This tool helps you generate common rules for your .htaccess file, which is a configuration file for the Apache web server. Select the rules you need, and the corresponding code will be generated instantly.

  1. Select Your Rules: Use the checkboxes and radio buttons to enable the rules you want for redirects, caching, and security.
  2. Copy the Code: The output contains all your selected rules, organized and commented. Click the "Copy" button.
  3. Update Your File: Paste the code into your .htaccess file and upload it to the root directory of your website. Always back up your existing .htaccess file before making changes.

What is an .htaccess file?

An .htaccess (hypertext access) file is a directory-level configuration file that allows for decentralized management of web server configuration. It can be used to override global server settings for a specific directory and its subdirectories. It is most commonly used to handle URL rewriting, redirects, access control, and caching policies.

Important: .htaccess files are only used by Apache web servers. They will have no effect on servers running Nginx or other web server software.

Generated Rules Explained

  • Force HTTPS: This rule checks if a request is not secure (not using HTTPS) and issues a permanent redirect (301) to the https:// version of the same URL. This is essential for modern SEO and security.
  • Resolve WWW: This ensures that all visitors see the same version of your domain, either with the www. prefix or without it. This is important for SEO to prevent search engines from seeing two different "duplicate" versions of your site.
  • Browser Caching: These rules tell the visitor's browser how long it should "remember" certain types of files (like images, CSS, and JavaScript). When the user revisits your site, their browser can load the files from its local cache instead of re-downloading them, making the site load much faster.
  • Deny Directory Listing: By default, if a user navigates to a directory on your server that doesn't have an index file (like index.html), Apache will show a list of all the files in that directory. This rule disables that feature, which is a good security practice.
  • Protect .htaccess File: This rule prevents web visitors from being able to view the contents of your .htaccess file by typing its URL in their browser.
  • Prevent Image Hotlinking: Hotlinking is when another site embeds an image from your site by linking directly to its URL. This uses your server's bandwidth. This rule blocks requests for images that do not originate from your own domain.

A Word of Caution

The .htaccess file is a powerful configuration file. A small typo or incorrect rule can cause your entire website to become inaccessible (often resulting in a "500 Internal Server Error"). Remember, always make a backup of your working .htaccess file before you edit it. If you upload a new version and your site breaks, you can simply restore the backup to get it working again.