.htaccess Code Generator

The .htaccess file is a powerful configuration file used on Apache servers to control various aspects of website functionality, including redirects. This tool allows you to generate .htaccess rules for redirecting traffic from www to non-www or from non-www to www.


  1. Choose the type of redirection you want: either redirecting from www to non-www or from non-www to www.
  2. Enter your domain name (without http:// or www.) in the provided input field.
  3. Click on the “Generate .htaccess Rules” button to generate the corresponding .htaccess rules.
  4. The generated rules will appear in the text area below.
  5. You can copy the generated rules to your clipboard by clicking the “Copy” button.


Let’s say your domain is example.com. If you choose to redirect from www to non-www, the generated rules would look like this:

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


  • Ensure that you have Apache mod_rewrite enabled on your server for these rules to work.
  • Always test the generated rules on a development or staging environment before applying them to your production server.