Ultra Web Hosting

Htaccess Generator

Free Apache .htaccess generator. Toggle common rules — force HTTPS, www/non-www redirects, 301 redirects, custom error pages, IP blocking, hotlink protection, browser caching and gzip — and copy a ready-to-paste .htaccess file.

Apache .htaccess Generator

Toggle the rules you need and copy a ready-to-paste .htaccess file. Everything is built live in your browser — nothing is sent to our server. Rules are wrapped in <IfModule> guards and use valid Apache 2.4 syntax.

Primary Domain
Used by the www redirect and hotlink-protection rules.
Redirects all http:// traffic to https:// (301). Requires a valid SSL certificate.
Pick one canonical hostname. Needs the Primary Domain field set above.
Old path is relative to your site root (e.g. /old-page.html). New target can be a path or a full URL.
Leave a field blank to skip that code.
Uses modern Apache 2.4 Require syntax. A legacy Order/Deny block is added as a comment for old servers.
Adds Options -Indexes so visitors cannot list folder contents that lack an index file.
Space-separated. The first file that exists in a folder is served.
Sets far-future expiry headers for images, CSS, JS and fonts so returning visitors load faster.
Compresses text-based responses (HTML, CSS, JS, JSON, SVG, XML) to cut transfer size.
Serves these files with Content-Disposition: attachment instead of opening in the browser.
Your .htaccess
# Enable rules on the left to build your .htaccess file.
On Ultra Web Hosting our stack runs NGINX in front of Apache. These mod_rewrite redirect rules and <IfModule> blocks still work — Apache processes the .htaccess normally. Upload it to your site's document root (e.g. public_html).
Share: X in Reddit f Email

About This Tool

The .htaccess file is a per-directory configuration file read by the Apache web server. It lets you control how your website behaves without touching the main server configuration: redirecting visitors, forcing HTTPS, choosing a canonical www or non-www hostname, serving custom error pages, blocking abusive IP addresses, stopping image hotlinking, and enabling browser caching and gzip compression for faster page loads. Writing .htaccess rules by hand is error-prone because a single typo can take an entire site offline with a 500 error. This generator builds correct, well-commented Apache 2.4 syntax for you, entirely in your browser, so nothing you type is ever sent to our server.

How to Use

Enter your primary domain at the top, then flip on the rules you want using the toggles on the left. Each section reveals its own options: choose www or non-www, add as many old-to-new redirect rows as you need with a 301 or 302 status, list IP addresses to block one per line, and so on. As you make changes, the combined .htaccess file rebuilds live on the right with a clear comment header above every section. When it looks right, click Copy to grab it or Download to save a ready-to-upload .htaccess file, then place it in your site document root (usually public_html).

Tips & Best Practices

Always back up your existing .htaccess before replacing it. Test the new file on a staging copy first if you can, because a bad directive returns a 500 error for every page. Force HTTPS and pick a single canonical hostname (www or non-www) so search engines do not treat both versions as duplicate content. Use 301 redirects for permanent moves so link equity passes to the new URL, and 302 only for temporary changes. On Ultra Web Hosting our stack runs NGINX in front of Apache, but Apache still reads and applies your .htaccess normally, so these mod_rewrite redirects and IfModule blocks work as written. If a rule seems to have no effect, confirm the relevant module (mod_rewrite, mod_expires, mod_deflate, mod_headers) is enabled on your server.

Need reliable hosting? These free tools are brought to you by Ultra Web Hosting. Fast, secure shared and reseller hosting with 24/7 expert support. View hosting plans →