Pak Jiddat - Innovative Software Services

Read: In the name of thy Lord Who createth, Createth man from a clot. Read: And thy Lord is the Most Bounteous, Who teacheth by the pen, Teacheth man that which he knew not. Nay, but verily man is rebellious That he thinketh himself independent!. Lo! unto thy Lord is the return. (Sura Alalaq 96:8)

Redirect http to https with Apache

Created On: 24 Apr, 2018: 10:06:48 - Tags : web servers

Url: https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

To redirect http urls to https, we need to add the following directives to .htaccess file:


RewriteEngine On
# This will enable the Rewrite capabilities

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

RewriteRule {/?(.*) https://%{SERVER_NAME}/$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

Related Articles

  1. Creating and Installing Apache Self Signed Certificate
  2. Using flags with rewrite rule
  3. Redirecting without mod_rewrite using regular expressions in htaccess
  4. Generate Certificate Signing Request (CSR) for ssl certificates
  5. Disabling output buffering with mod_fcgid
  6. Configuring Apache mod status
  7. Allowing Cross Origin Requests using htaccess
  8. Redirect http to https with Nginx
  9. Access control directives for Apache
  10. Blocking visitors by http method using LimitExcept Apache directive
  11. Passing query parameters to proxy server in Nginx
  12. Use of Preflight request in HTTP Cross Origin Resourse Sharing (CORS)
  13. Using RewriteCond directives