Skip to content
GENERATORS

.htaccess Redirect Generator – HTTPS & www

Generate HTTPS and www redirect rules for Apache.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

.htaccess Generator

About .htaccess Generator

The .htaccess file lets you configure Apache without editing the server settings. The most common use is a 301 redirect that sends all visitors to one canonical version of the site, so search engines treat https://www.example.com or https://example.com as the single main address.

Choose HTTPS with www, HTTPS without www or HTTPS only. Each option writes mod_rewrite rules that redirect in a single step, so a visitor on http://www.example.com is not sent through the wrong host name. Place the rules at the top of your .htaccess file.

How to use .htaccess Generator

  1. Select the redirect you want from the dropdown.
  2. Click Run Tool to generate the rules.
  3. Back up your current .htaccess, paste the rules at the very top and test the site in a private window.

Common uses

  • Forcing HTTPS after installing an SSL certificate.
  • Choosing one canonical host name to avoid duplicate content between www and non-www.
  • Fixing mixed redirects after moving a site.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Where should the code go in a WordPress .htaccess?

Above the # BEGIN WordPress block, so the redirect runs before WordPress handles the request.

Why do I get too many redirects?

If your site is behind Cloudflare or a proxy using flexible SSL, the server may always see HTTP. Switch the SSL mode to Full, or test the X-Forwarded-Proto header instead of the HTTPS variable.

Does it work on Nginx?

No. These are Apache rules. Nginx needs equivalent return 301 directives in the server configuration.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.