Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Friday, November 20, 2009

Enable Mod Rewrite on WAMPSERVER

You need to enable Mod Rewrite in order to use pretty permalinks in WordPress or Clean URLs in Drupal.

However, WAMPSERVER does not enable Mod Rewrite by default.

To enable Mod Rewrite,
  1. Click on the WAMPSERVER icon in the system tray, and choose Apache.
  2. Click on Apache modules.
  3. Click on the down triangle until you see rewrite_module. Click to enable it.
  4. Restart All Services.
Figure 1 shows the steps graphically.

Figure 1: Steps to enable Rewrite Module on WAMPSERVER 

Saturday, August 1, 2009

How to enable Apache public_html for user on Ubuntu

Suppose that you want each user to have their own public_html in their home directory.

For example, user with username ahmad, can have his own Web site at

Enable mod_userdir

To achieve that, first, what you need to do is to enable mod_userdir, which is installed by default with Apache2.
sudo a2enmod userdir

Create public_html directory

Second, the user need to create public_html directory in their home directory.
mkdir public_html

Restart Apache

Finall, you should restart Apache.
sudo /etc/init.d/apache2 restart

Monday, April 27, 2009

Enable Ubuntu public_html user directory for Apache

The steps to make http://localhost/~username works in Ubuntu.

  1. Create public_html directory in home directory
    mkdir ~/public_html
  2. Enable the user directory
    cd /etc/apache2/mods-enabled
    sudo ln -s ../mods-available/userdir.conf userdir.conf
    sudo ln -s ../mods-available/userdir.load userdir.load
  3. Restart Apache
    sudo /etc/init.d/apache2 restart

Monday, August 18, 2008

9 ways to hide affiliate links

These codes are useful for hiding the affiliate links. However, please read the affiliate program terms of service, so that you won’t go against it.

For all except the last way (.htaccess redirect), create the respective file for each affiliate link with the code for the chosen redirect style. Replace ‘http://your-affiliate-link-goes-here’ with the URL of the affiliate link.

For example, if you choose to use the PHP redirect, first create a PHP file. Copy and paste the PHP redirect code into that file. Replace ‘http://your-affiliate-link-goes-here’ with the affiliate link URL.

Every time you want to link to the affiliate link, just link to that file.

You have to create new file for each affiliate link.

HTML redirect

<title>HTML Redirect</title>
<meta http-equiv="refresh" content="0;
Please wait. Redirecting...

PHP redirect

<?php header("Location: http://your-affiliate-link-goes-here"); ?>

ASP redirect

<%@ Language=VBScript %>
<% Response.AddHeader "Location","http://your-affiliate-link-goes-here" %>

ASP.NET redirect

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)

Coldfusion redirect

<.cfheader name="Location" value="http://your-affiliate-link-goes-here">

JSP redirect

<% response.setHeader( "Location", "http://your-affiliate-link-goes-here" );
response.setHeader( "Connection", "close" ); %>

cgi Perl redirect

$q = new CGI; print $q->redirect("http://your-affiliate-link-goes-here");

Ruby on Rails redirect

def old_action redirect_to "http://your-affiliate-link-goes-here" end

Apache .htaccess on Linux

Add this code to the end of .htaccess file. Replace ‘http://your-affiliate-link-goes-here’ with the affiliate link URL. To have more than one affiliate link, just add another RewriteRule.
RewriteEngine on RewriteRule ^affliate.php$
http://your-affiliate-link-goes-here [R]

Wednesday, April 16, 2008

Python: Parse Apache log to sqlite database

This Python script was written for a friend in Australia, as part of his Ph.D project. The script will parse the Apache server log into sqlite3 database.

Apache server log like this: - - [26/Sep/2007:21:20:36 +0800]
“GET /forum/Themes/BlueStory/images/bbc/ftp://ftp.gif HTTP/1.1? 200 191
“Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
Gecko/20070914 Firefox/
could be parse to an sqlite database, with the class below.
class Parser:
    def __init__(self, serverLog, db):
        if db.strip() == "":
        db = "log.db"
            conn = sqlite3.connect(db)
            cursor = conn.cursor()
            cursor.execute("create table if not exists log
            (ip, date, time, gmt, request,
            errorcode, bytes, referel, osa)" )
        except sqlite3.Error, error:
            wx.MessageBox(str(error), "Info")

        numLog = len(open(serverLog).readlines())
        for line in open(serverLog, "r"):
            data = []
            a = line.split(‘"‘)
            line = line.split()


        data.append(line[3][line[3].index(":") + 1:])


        data.append(line[5][1:] + " " + line[6])


        data.append(line[9]) #bytestr data.append(line[10][1:-1])


            cursor.execute( "insert into log values(
             ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            (data[0], data[1], data[2], data[3],
            data[4], data[5], data[6],
            data[7], data[8]) )
        except sqlite3.Error, error:
            wx.MessageBox(str(error), 'Info')