@
you're reading...
Apache, Linux Tips and Tricks

Redirect HTTP traffic to HTTPS

You will find the need to implement a redirection of HTTP request to HTTPS. With this all you need to use is Apache’s mod_rewrite module. Below is the sample configuration for both the entire site or just a sub section.

To redirect ALL traffic to HTTPS:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

To redirect traffic to a sub section or directory(in this case we want to redirect users who are trying to reach /secure)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?secure/(.*) https://%{SERVER_NAME}/secure/$1 [R,L]

Advertisements

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s