Thursday, June 21, 2007

Switching between HTTP and HTTPS

Question:

Following statements are there in my Apache2 virtual hosts section

Redirect /host/directory/folder/login.php https://servername/host/directory/folder/login.php
Redirect /host/directory/folder/register.php https://servername/host/directory/folder/register.php

How to return to http (not https) when the above 2 pages are not involved?

Answer:

In HTTP VH:
RewriteRule /.../login.php https://.../login.php [R]
RewriteRule /.../register.php https://.../register.php [R]

In HTTPS VH:
RewriteRule /.../login.php - [S=2]
RewriteRule /.../register.php - [S=1]
RewriteRule ^/(.*) http://servername/$1 [R]

In the HTTPS VH, if you get login.php or register.php you don't rewrite it (the "-"), then you skip the next 2 or 1 RewriteRules ( [S=2], [S=1]) - that is, you skip over the general purpose rewrite back to HTTP. So login.php or register.php get served from HTTPS and everything else goes back to HTTP.

Thursday, June 07, 2007

Perl Code Profiling - Apache::DProf


  1. In Startup.pl:
       # The Apache::DProf requires this
    use Apache::Registry;

  2. In conf:
       PerlModule Apache::DProf

  3. Make sure the logs directory has write rights

  4. Restart Apache & do whatever you want in the browser page

  5. Stop Apache (only then the tmon.out will get complete output)

  6. Go to the directory where tmon is (logs/dprof//) and run dprofpp

Refer: Code Profiling Techniques

Monday, June 04, 2007

Apache and strace

To display a trace of system calls. Useful for debugging.

root@sri# apachectl stop (First stop Apache and then restart Apache with strace)
root@sri# strace -f -o trace.txt /etc/rc.d/init.d/httpd start

-f: Traces child processes as they are created by currently traced processes.

-o: Outputs to a text file