0

I have uploaded a wordpress website to Google Cloud Platform using a VM instance.

I have made the redirection of http to https . Although I can not make the redirerction of www to https, using the method of .htaccess

Can anyone help me out?

Thank you in advance!

  • I have used this code but doesn't word: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] – Johny Arduino Oct 05 '21 at 19:13
  • You can try with the below code - RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] – phpdev Oct 05 '21 at 19:16
  • At this point, nobody can help you. Also, you probably haven't searched this site too well. There are at least a few answers https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www – Howard E Oct 05 '21 at 19:20
  • Hi sorry, I am also using cloudflare. – Johny Arduino Oct 05 '21 at 19:23
  • I used this code but does nothing RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] – Johny Arduino Oct 05 '21 at 19:24
  • Will I need to restart the VM for the changes to apply? – Johny Arduino Oct 05 '21 at 19:30

2 Answers2

0

Change with the following

 RewriteEngine on
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
    RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]

refer: https://wpengine.com/resources/wordpress-redirects/

PHP Geek
  • 3,949
  • 1
  • 16
  • 32
0

I found the solution.

I have made a Page Rule inside cloudflare and I redirect all the traffic from WWWW to non-WWW .

So it is solved.