Web 2.0 网站架构、优化 数据库架构
« »
2009年12月16号Lecture

Redirect HTTP To HTTPs with mod_rewrite

We all knows HTTPS is the use of Secure Socket Layer (SSL) or Transport Layer Security (TLS) as a sublayer under regular HTTP application. The HTTPS protocol encrypts and decrypts user’s page requests as well as the pages that are returned back by the Web server.

In this little tutorial We will show you how we can redirect our normal http traffic to https using apache mod_rewrite module.

We will implement this howto on a webmail. We want to protect our user’s information such as username & password, lets say we have url http://mail.techbabu.com and we want to redirect it to https://mail.techbabu.com and we also don’t want to bother our client that they should use type https instead of http whenever they want to check their emails

So then we need some special and that is mod_rewrite, This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. You can learn here about mod_rewirte.

You need to configure SSL in Apache web server, A working SSL based Apache should be running. We will not discuses here about how to configure SSL.

Make sure your Apache compiled with (mod_rewirte) module. If not then you need to recompile your Apache with mod_rewrite module support.

Let’s edit httpd.conf file and uncomment this line

LoadModule rewrite_module libexec/apache22/mod_rewrite.so

Now add these lines in htttpd.conf file for redirecting http to https

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

日志信息 »

该日志于2009-12-16 21:14由 admin 发表在Lecture分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

没有评论

发表评论 »

返回顶部