.htaccess Generator
Generate common `.htaccess` rules for your Apache server easily. Select the options you need and copy the generated code.
Generated Code
Copy this code into a file named `.htaccess` (note the dot at the beginning) in your website's root directory. **Backup your existing `.htaccess` file first!** Incorrect rules can break your site.
What is an .htaccess File?
An `.htaccess` (hypertext access) file is a configuration file used by the Apache web server. It allows you to define rules and directives that control how the server behaves for a specific directory and its subdirectories, without needing to edit the main server configuration files.
You can place an `.htaccess` file in any directory on your server (commonly the root directory) to apply rules like password protection, URL rewriting, custom error pages, blocking access, forcing HTTPS, and more.
Common Uses Relevant to SEO
- Redirects (301): Permanently redirect old URLs to new ones, crucial for preserving link equity during site changes or migrations. This includes forcing WWW or non-WWW versions and enforcing HTTPS.
- Custom Error Pages: Define user-friendly pages for errors like 404 (Not Found) or 500 (Server Error) instead of generic server messages.
- URL Rewriting (`mod_rewrite`): Create clean, SEO-friendly URLs by rewriting dynamic URLs (e.g., `product.php?id=123`) into static-looking ones (e.g., `/products/widget/`).
- Directory Browsing Control: Prevent visitors from seeing a list of files in a directory if no index file (like `index.html`) exists.
- Hotlink Protection: Prevent other websites from directly linking to your images or files, saving bandwidth. (Not included in this basic generator).
Important: Always back up your existing `.htaccess` file before uploading a new one. A small mistake in the syntax can make your website inaccessible.