.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.
Instructions
- Choose the type of redirection you want: either redirecting from www to non-www or from non-www to www.
- Enter your domain name (without http:// or www.) in the provided input field.
- Click on the “Generate .htaccess Rules” button to generate the corresponding .htaccess rules.
- The generated rules will appear in the text area below.
- You can copy the generated rules to your clipboard by clicking the “Copy” button.
Example
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]
Notes
- 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.