What Does the Htaccess Redirect Generator Do?
Your site can usually be reached at both example.com and www.example.com. Search engines may treat these as two separate sites, splitting links and creating duplicate content. A permanent redirect picks one version and sends every visitor to it.
This htaccess redirect generator writes the Apache mod_rewrite rules for that redirect. Choose non-www to www or www to non-www, enter your domain, and copy the code into the .htaccess file in your site's root folder. The rules use a 301 (permanent) redirect and keep the rest of the path.
How to Create an Htaccess Redirect
- 1Select the redirect type — non-www to www, or www to non-www.
- 2Enter your domain — as a full URL, for example https://example.com.
- 3Click Get Your HtAccess Code — to generate the rules.
- 4Add it to .htaccess — copy the code or save it as TXT, then paste it into the .htaccess file in your site root.
Why Use This Redirect Generator?
No regex to write
Get working RewriteCond and RewriteRule lines without learning mod_rewrite syntax.
Both directions covered
Generate rules for whichever version of your domain you want to keep.
Path is preserved
Visitors to any page land on the same page on your preferred domain.
Copy or save
Copy the rules to your clipboard or download them as a text file.