Directive | Purpose | Example Usage | Common Use Case |
---|---|---|---|
RewriteEngine | Enable URL rewriting | RewriteEngine On | Required for all redirect rules |
RewriteRule | Define URL rewrite patterns | RewriteRule ^old$ /new [L,R=301] | 301 redirects, clean URLs |
RewriteCond | Set conditions for rewrites | RewriteCond %{HTTPS} off | Conditional redirects (HTTPS, WWW) |
Redirect | Simple redirects | Redirect 301 /old /new | Basic page redirects |
Header | Set HTTP headers | Header set X-Frame-Options DENY | Security headers, caching |
Options | Server behavior settings | Options -Indexes | Disable directory listing |
ErrorDocument | Custom error pages | ErrorDocument 404 /404.html | User-friendly error pages |
ExpiresActive | Enable expiration headers | ExpiresActive On | Browser caching setup |
AddOutputFilterByType | Apply compression | AddOutputFilterByType DEFLATE text/html | Gzip compression |
Require | Access control | Require not ip 192.168.1.1 | IP blocking, authentication |
wp-config.php
.htaccess
file itselfwp-includes
directoryreadme.html
and license.txt
Always create a backup before making changes. Download your existing .htaccess file and save it in a safe location.
Place your .htaccess file in your website's root directory (usually public_html, www, or your domain folder).
Set file permissions to 644 (readable by owner, readable by group and others) for security.
Check all important pages, forms, and functionality. Test redirects and security rules to ensure they work correctly.
Cause: Syntax error in .htaccess file
Solution: Rename .htaccess to .htaccess-off via FTP, then fix syntax errors
Cause: Conflicting redirect rules
Solution: Check RewriteRule order and conditions, avoid duplicate redirects
Cause: Overly restrictive access rules
Solution: Temporarily rename .htaccess, access admin, then adjust rules
Cause: Complex .htaccess rules
Solution: Optimize regex patterns, remove unnecessary rules, test performance
An .htaccess file is a configuration file for Apache web servers that controls how your website behaves. You need it to redirect URLs, force HTTPS, improve security, enable caching, and optimize performance. It's essential for WordPress sites and any website wanting better SEO and security.
Upload your .htaccess file to your website's root directory (usually public_html, www, or your domain folder). This is the same folder where you'll find index.php or index.html. The file must be named exactly ".htaccess" (with the dot at the beginning).
A properly generated .htaccess file won't break your website. However, incorrect syntax can cause issues. Always backup your existing .htaccess file before making changes. If your site breaks, simply rename the .htaccess file via FTP to restore access, then fix any errors.
Add these lines to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Our generator creates this code automatically when you select "Force HTTPS" option.
.htaccess files work on Apache servers and some Nginx servers with proper configuration. Most shared hosting providers support .htaccess. However, some managed hosting services (like WordPress.com) don't allow custom .htaccess files. Check with your hosting provider if unsure.
Use .htaccess to protect wp-config.php, block access to wp-admin for unauthorized users, prevent PHP execution in uploads folder, disable directory browsing, and add security headers. Our generator includes pre-built WordPress security rules you can enable with one click.
Set .htaccess file permissions to 644 (rw-r--r--). This allows the owner to read and write, while others can only read. Never use 777 permissions as this creates security vulnerabilities. Most FTP clients and hosting control panels allow you to change file permissions easily.
Yes, ServerAvatar's Apache .htaccess generator is completely free to use. You can generate, copy, and download .htaccess files without any cost, registration, or limitations. The tool includes all features for security, performance, and redirect configurations.