Htaccess Redirect
Our free tool generates .htaccess code to redirect...
Share on Social Media:
To redirect a domain without www to www, you can add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
This code will redirect all requests to the domain without www to the corresponding URL with www. For example, a request to example.com
will be redirected to www.example.com
.
To redirect a domain with www to without www, you can add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
This code will redirect all requests to the domain with www to the corresponding URL without www. For example, a request to www.example.com
will be redirected to example.com
.