0

Can any one please help me how redirect all http://example.com and http://www.example.com to https://www.example.com. I have recently purchased an ssl for my site and hence needed it to be redirected. Redirecting using .htaccess will be more useful for me. Thanks in advance.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
Punit Makwana
  • 485
  • 1
  • 6
  • 13
  • 1
    There are several answers linked under `Related` on RHS. Did you try any of them? – anubhava Mar 19 '15 at 14:33
  • Like @anubhava said, there are a lot of answers on the site for this questions. – ben Mar 19 '15 at 15:24
  • possible duplicate of [Force SSL/HTTPS with Zend Framework and mod\_rewrite](http://stackoverflow.com/questions/1329647/force-ssl-https-with-zend-framework-and-mod-rewrite) – ben Mar 19 '15 at 15:26

1 Answers1

0

There are a lot of solutions out there. Here is a link to the apache wiki which deals with this issue directly.

http://wiki.apache.org/httpd/RewriteHTTPToHTTPS

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*)$ https://www.example.com/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
Amit Verma
  • 40,709
  • 21
  • 93
  • 115