2

I am trying to force domain URL to use www always in WordPress Multisite.

For example if some one type abc.com then it should be redirect automatically to www.abc.com

I have used the following rules in htaccess but it works only for main domain in WordPress Multisite and not for other sub domains.

# Canonical https/www
<IfModule mod_rewrite.c>    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

So any help on this, is highly appreciated in advance.

Deepak Lakhara
  • 323
  • 2
  • 9

1 Answers1

1

Can you try this ?

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Ryan AR
  • 79
  • 1
  • 4
  • this seems working. Will you please explain what is the difference between my code and your code as it seems same expect the and thanks again for your help. – Deepak Lakhara Dec 15 '21 at 14:02
  • 1
    There is an additional ^ after RewriteRule. – Ryan AR Dec 15 '21 at 14:16
  • thank you sir for explaination. Will you guide me some documentation for htaccess rules to read. It will be helpful. – Deepak Lakhara Dec 15 '21 at 14:28
  • 1
    Sure. Always test your redirects in https://htaccess.madewithlove.com. Make sure you accept the answer if it is working. – Ryan AR Dec 15 '21 at 14:30
  • 2
    There is no difference between your rule and the rule posted by OP. The pattern without `^` is same as its without it. – Amit Verma Dec 15 '21 at 14:37