2

I would like to make a redirection to https://www.

Which means that:

http:// --> https://www.
http://www. --> https://www.
https:// --> https://www.
https://www. --> no redirection

I tried plenty of things but never reached that goal.

my current .htacces:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

But the problem is that it doesn't redirect to www. So I tried to put that before :

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ www.%{HTTP_HOST}/$1 [R=301,L]

But that made a redirection curl so shut my site down.

PS: I'm on symfony

Does someone have the magic solution ? Thank's !

J.K
  • 1,382
  • 1
  • 11
  • 27
Fab
  • 668
  • 9
  • 24

1 Answers1

0

You can use these rules to enforce both https andwww`:

RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I did but it's not taken in account because I don't have 15 likes.. sorry – Fab May 06 '16 at 10:00
  • No you don't need 15 reps to accept an answer that is for upvoting. You can mark the answer as accepted **by clicking on tick mark on top-left of this answer** and it will turn green – anubhava May 06 '16 at 10:04