In some cases, web applications don't handle redirects from non-www to www, or reverse - if that's the case, you'll have to do it using rewrite rules in the .htaccess file for the website.
If you want to redirect all domains pointing on the same directory from non-www to www, you can do like the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
If you only want to redirect a specific domain, you can use the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
If you want to redirect from www to non-www, you can use the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Or a specific domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule (.*) https://example.com/$1 [R=301,L]
Comments
0 comments
Please sign in to leave a comment.