Jeevan Roy dsouza
Jeevan Roy dsouza

Reputation: 673

Redirecting all http requests to https in apache

I am using Apache in server side.I want to redirect all HTTP requests which are coming to server into HTTPS.

My question: How i can configure httpd.conf for This? For Example:Suppose user entered http://doc.com/ i want redirect it to https://doc.com/

Upvotes: 0

Views: 125

Answers (2)

mirabilos
mirabilos

Reputation: 5317

This requires mod_rewrite but is able to keep query strings:

RewriteEngine On
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

This doesn’t and is lighter on the server:

RedirectMatch permanent ^(.*)$ https://doc.com/$1

If you just want to redirect all nōn-HTTPS requests to the start page, use:

RedirectMatch permanent . https://doc.com/

Upvotes: 2

Jeevan Roy dsouza
Jeevan Roy dsouza

Reputation: 673

RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

Upvotes: 0

Related Questions