.htaccess Generator
Create Apache .htaccess configuration text with redirect rules, cache-expiration directives, security headers, and custom rules. Paste the generated output into your server file.
Run tool
The .htaccess Generator builds Apache configuration text you can copy into your .htaccess file. It is useful when you need to force HTTPS, force the www version of your domain, set browser caching, add security headers, or append your own rules. You choose a redirect mode from the menu: none, force HTTPS, force WWW, or custom redirect. For a custom redirect, you supply the destination URL, and the tool inserts it into a 301 rule that preserves the captured path. The cache control field accepts a value such as 1 month or 2 days, and the tool places it into an Apache expiration block. When you enable security headers, the output includes directives for nosniff content-type protection, deny framing, and XSS protection. Any non-whitespace custom rules you enter are appended after a marker, exactly as typed. The tool does not validate, escape, or test the generated configuration, and it does not deploy anything to your server. After you click Run, the result panel shows the complete configuration text, ready for you to review and save.
Instructions
- Open the .htaccess Generator page.
- Choose a redirect mode from the Redirect Mode menu. Select None if you do not need a redirect.
- If you chose Custom Redirect, type the destination URL in the Redirect URL field.
- Optional: enter a cache duration, such as 1 month, in the Cache Control field.
- Optional: turn on Security Headers to add nosniff, deny framing, and XSS protection directives.
- Optional: paste any custom rules you want appended in the Custom Rules field.
- Click Run to generate the configuration text.
- Copy the output and paste it into your .htaccess file on the server.
Examples
- Force HTTPS: select Force HTTPS, leave other fields empty, click Run. The output includes a rewrite rule that redirects requests with HTTPS off to the same host using HTTPS, with a 301 status.
- Force WWW: select Force WWW, click Run. The output adds a case-insensitive 301 rule that redirects the captured path to www.example.com over HTTPS.
- Custom redirect: select Custom Redirect, enter https://newdomain.com in Redirect URL, click Run. The output contains a 301 redirect rule that sends the captured path to that URL.
- Set caching: enter 1 month in Cache Control, click Run. The output includes an Apache expiration block with access plus 1 month.
- Add security headers: turn on Security Headers, click Run. The output includes directives for nosniff, deny framing, and XSS protection.
FAQ
Does the tool deploy the .htaccess file to my server?
No. The tool only generates configuration text. You copy the output and place it in your .htaccess file yourself.
What happens if I enter a custom redirect URL?
The tool inserts that URL into a 301 redirect rule, preserving the captured path. It does not validate or escape the URL, so make sure it is correct.
Can I use a cache value like 2 days?
Yes. Any value you enter in the Cache Control field is placed into the expiration text. The tool does not check the format, so use a value Apache understands, such as 1 month or 2 days.
What are security headers?
When enabled, the output includes directives for nosniff content-type protection, deny framing, and XSS protection. These are common hardening measures, but the tool does not guarantee security completeness.
How do I add my own rules?
Type your rules in the Custom Rules field. Non-whitespace text is appended after a marker, exactly as you entered it. The tool does not transform or validate the rules.