HTAccess Rewrite Rule Generator

HTAccess Rewrite Rule Generator

HTAccess Rewrite Rule Generator

Create rules to redirect www to non-www URLs or vice versa with proper HTTPS redirection

About the Rewrite Rule

The following code is an Apache .htaccess rewrite rule that redirects requests from www to non-www version of a domain with HTTPS enforcement:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

What this code does:

  • RewriteEngine On – Enables the rewriting engine
  • RewriteCond – Checks if the HTTP_HOST matches www.example.com (case-insensitive)
  • RewriteRule – Redirects to the non-www HTTPS version with a 301 (permanent) status
  • [NC] – Makes the condition case-insensitive
  • [L] – Stops processing further rules if this one matches
  • [R=301] – Performs a 301 (permanent) redirect

Note: This rule must be placed in the .htaccess file in your website’s root directory. Make sure your server has the mod_rewrite module enabled.

Generate Your Rule

Your Generated Rule:

Copy this code into your .htaccess file

HTAccess Rewrite Rule Generator Tool | Created for web developers