1

My problem is when I type example.com or www.example.com in browser it redirect to https://example.com but when I type https://www.example.com, it doesn't redirect to https://example.com.

I want whatever may be the url http or https and www or non www, it always point to https://example.com.

I have used below url rewrite for htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

Thanks in advance.

RavinderSingh13
  • 101,958
  • 9
  • 41
  • 77
Deb
  • 383
  • 1
  • 3
  • 12

1 Answers1

2

With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.

Also make sure this should be your TOP MOST rule in your .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,R=301,L]

This should redirect urls irrespective of either url has http or https OR url has www or no www in it TO https without www.

RavinderSingh13
  • 101,958
  • 9
  • 41
  • 77