0

I have tried to move my wordpress website to https.

I have dedicated ip also first i had this code below. But did'nt resolve my problem exactly

    RewriteEngine On
RewriteCond %{HTTP_HOST} ^11\.11\.11\.11$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Later on I had this code which resolved url redirection problems But later on ı had the same problems about when somebody cliks a http link given before doesnt go to https url.

    <IfModule mod_rewrite.c>
RewriteEngine on
#First rewrite any request to the wrong domain to use the correct one (here www.)

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

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

And another question is how i will redirect ip to https? And where i must put that?

JosePinheiro
  • 39
  • 1
  • 9
  • You should do two rewrites - one to apply the correct domain, and another to apply HTTPS. [Here is a complete example](http://stackoverflow.com/a/13997498/541091), and you may add your `[OR]` condition as well to match the IP address. – Michael Berkowski Dec 26 '15 at 22:50
  • I have seen that. without ip works great. – JosePinheiro Dec 27 '15 at 14:16
  • What action should be taken when the IP is sent? Should it be redirected to the www domain with HTTPS? If so, you would need to add a 3rd rule to the linked answer which just handles the IP. Otherwise, it would first attempt to redirect the IP to HTTPS, which would be an SSL error for the browser. – Michael Berkowski Dec 27 '15 at 16:00
  • yes should be redirected to the www domain with https. What will be the 3rd rule? I have tried many things. – JosePinheiro Dec 27 '15 at 19:23
  • Probably before any other rules, do something like `RewriteCond %{HTTP_HOST} 11\.11\.11\.11 RewriteRule ^(.*) https://www.example.com/$1 [L]` – Michael Berkowski Dec 28 '15 at 12:25
  • This one worked. Thank you very much. I was doing same before but not as a separate cond and rule. You can enter your reply soi can chose yours. – JosePinheiro Dec 29 '15 at 05:15
  • Possible duplicate of [htaccess redirect to https://www](http://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www) – Michael Berkowski Dec 29 '15 at 13:44

2 Answers2

1
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

should indeed work

JoYiDer
  • 63
  • 8
0

I used a plugin called Really simple SSl And that entered this code.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

and before all (as mentioned by Michael Berkowski )

RewriteCond %{HTTP_HOST} 11\.11\.11\.11 
RewriteRule ^(.*) https://www.example.com/$1 [L]

thanks to participants

Community
  • 1
  • 1
JosePinheiro
  • 39
  • 1
  • 9