-1

I want to rewrite and redirect my http:\\www.domain.tld to https:\\www.domain.tld

And I want to rewrite and redirect my domain.tld to www.domain.tld

I want to have something that redirect and, with seo concern, shows that's a redirection.

For now I have something like this:

1)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE,QSA]

or

2)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE,QSA]

What's the best? Is there something wrong?

Thank you

user2314737
  • 27,088
  • 20
  • 102
  • 114
Canard
  • 1
  • Questions about that are answered every week, do so research, there are **many** working configurations detailed out there. – Nic3500 Nov 08 '18 at 05:35
  • :-/ sorry but I didn't find this example (with www) and i struggle to apply the other examples I found... so I wanted just to know if what i propose is correct. – Canard Nov 08 '18 at 08:36

1 Answers1

0

The Apache docs recommend against using a rewrite: redirect to https

To redirect http URLs to https, you should do the following:

<VirtualHost *:80>
ServerName www.example.com
Redirect / https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
ServerName www.example.com
# ... SSL configuration goes here

This snippet should go into main server configuration file, not into .htaccess as asked in the question.

But if you don't have access to the main server configuration file you could use this:

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

Line 1: if the url starts without www

line 2: if there is no https

line 3: rewrite all urls from this domain to one that starts with https and have www

WendiT
  • 595
  • 2
  • 9
  • 26