An .htaccess file is a powerful Apache server configuration file that controls redirects, security, caching, and performance for your website. Instead of editing raw directives by hand, use this generator to visually toggle the rules you need — then copy the finished file directly to your server.
Configure Rules
Generated .htaccess
How to deploy
Copy the generated code, save it as .htaccess and upload it to the root of your website (public_html or www folder). Requires an Apache server with AllowOverride All enabled.
How to Use the .htaccess Generator
An .htaccess file is one of the most powerful configuration tools available to Apache web server users. It lets you control redirects, security rules, caching behaviour, and server settings for individual directories without needing root access to the server. This generator lets you build a complete, production-ready .htaccess file in seconds by toggling the sections you need.
Step 1: Enable the Sections You Need
Toggle each section on the left panel to enable or disable it. When a section is enabled, any additional settings (such as redirect destinations, IP addresses, or cache durations) expand below the toggle. Every change is reflected instantly in the generated output panel on the right.
Step 2: Configure HTTPS and www Redirects
Enable Force HTTPS to redirect all HTTP traffic to HTTPS using a 301 permanent redirect. This is essential for SEO and browser security indicators. Enable Force www / non-www to pick your preferred URL format and redirect the other version to it. Consistent canonical URLs prevent duplicate content penalties in search engines. Always enable HTTPS first before enabling the www redirect to avoid redirect chains.
Step 3: Add Performance Rules
Enable GZIP Compression to activate Apache's mod_deflate module, which compresses HTML, CSS, and JavaScript responses before sending them to the browser. This typically reduces page weight by 60–80% for text-based assets. Enable Browser Caching to set Expires headers on static files like images, CSS, and fonts. Choose a cache duration — 1 month is a sensible default for most assets that don't change frequently.
Step 4: Set Up Custom Error Pages and Redirects
Enable Custom Error Pages and enter paths to your custom HTML error pages for HTTP status codes 400, 401, 403, 404, and 500. Custom error pages improve user experience and keep visitors on your site when something goes wrong. Use the URL Redirects section to add one or more 301 redirects from old paths to new URLs — useful when restructuring your site or changing page URLs after a redesign.
Step 5: Secure Your Server
Enable Block IP Addresses to deny access from specific IPs, useful for blocking abusive bots or crawlers. Enable Hotlink Protection to prevent other websites from directly embedding your images, which wastes your bandwidth. Enter your domain name and the rule will only allow image requests originating from your own site. Enable Directory Listing to explicitly disable the default Apache behaviour of listing folder contents when no index file exists — this is a security best practice.
Step 6: Copy and Deploy
Click the Copy button to copy the generated .htaccess content to your clipboard. Open a text editor, paste the content, and save the file as .htaccess (note the leading dot — no file extension). Upload it to the root of your website using FTP or your hosting control panel's file manager. The file takes effect immediately without a server restart.
Frequently Asked Questions
What is an .htaccess file and what does it do?
An .htaccess file is a directory-level configuration file for Apache web servers. It lets you control server behaviour for a specific directory and its subdirectories without editing the main httpd.conf file. Common uses include URL redirects, forcing HTTPS, enabling GZIP compression, setting browser caching headers, blocking IP addresses, and customising error pages like 404s.
Is this .htaccess generator free to use?
Yes, completely free. All processing happens in your browser — no data is sent to any server. You can generate as many .htaccess files as you need with no account, no signup, and no usage limits.
Is my server configuration data safe?
Yes. The generator runs entirely in your browser using JavaScript. Your server settings, IP addresses, and redirect rules never leave your device. Nothing is transmitted to any external server.
Where do I put the .htaccess file on my server?
Place the .htaccess file in the root of your website (the public_html, www, or htdocs folder). It applies to that directory and all subdirectories. You can also place separate .htaccess files in subdirectories to apply different rules to specific sections of your site.
Will .htaccess rules work on my hosting provider?
.htaccess files work on any hosting environment running Apache with the AllowOverride directive enabled. Most shared hosting providers (cPanel, Plesk, etc.) support .htaccess by default. Nginx servers do not use .htaccess — they use server block configuration files instead. If you are unsure, contact your hosting provider.
How do I force HTTPS using .htaccess?
Enable the 'Force HTTPS' option in the generator. This adds a RewriteRule that permanently redirects all HTTP traffic to HTTPS using a 301 redirect, which also passes link equity for SEO purposes. Make sure your SSL certificate is installed before enabling this redirect to avoid redirect loops.
What is the difference between www and non-www redirect?
When you force www, all visitors to example.com are redirected to www.example.com. Forcing non-www does the opposite. Both use a 301 permanent redirect. Pick one and stay consistent — mixing www and non-www creates duplicate content issues in search engines. Set your preferred version as the canonical URL in Google Search Console as well.
How does browser caching in .htaccess work?
Browser caching rules set Expires and Cache-Control headers on static assets like images, CSS, and JS files. When a visitor loads your page, these assets are cached locally so they don't need to be re-downloaded on future visits. This improves page load times and reduces server load. The generator lets you choose expiry durations like 1 month, 6 months, or 1 year.