Thứ Hai, 27 tháng 4, 2009

Một bài viết hay(nên đọc)

Ngày xưa, có một câu chuyện về người cha trong ngày sinh nhật của đứa con 3 tuổi. Đứa con khư khư giữ những quà tặng, không cho các bạn chơi cùng. Người cha quyết định dạy con mình biết chia sẻ bằng cách giật đồ chơi khỏi tay đứa con cho những đứa khác. Có một điều mà người cha đó quên: trước khi học cách chia sẻ, đứa bé phải học cách sở hữu. Người ta không thể cho đi cái gì người ta không có. Cũng vậy, người ta không thể thoát khỏi bức tường mà người ta không nhìn thấy.

... Bạn sẽ cảm thấy rất đau khi bạn thât sự thương yêu một người mà người ấy lại không yêu bạn. Nhưng cái ấy còn chưa đau bằng nếu bạn thật sự thương yêu một người nhưng lại không có can đảm để nói cho người đó biết. Có thể là Thượng Đế, ngài muốn chúng ta quen trước những người mà không phải thuộc về mình trước khi cho mình gặp được “người bạn trăm năm” để cuối cùng mình sẽ biết quý trọng người đó hơn.

Con người sinh ra không phải để tan biến đi như một hạt cát vô danh

Họ sinh ra để in dấu lại trên mặt đất, in dấu lại trong trái tim người khác. Bạn có thể bị tổn thương nếu yêu một người một cách say đắm, nhưng nó là phương pháp duy nhất khiến con người bạn trở nên toàn diện. Đừng che giấu tình yêu và sự dịu dàng của mình cho đến khi bạn lìa đời. Hãy làm cuộc đời bạn tràn đầy sự ngọt ngào. Hãy nói những lời nói thân thương khi bạn còn nghe được và khi tim bạn còn rung động

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Đổi server name là̀ localhost -> mysql

Using Multiple JavaScript Onload Functions

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
/* more code to run on page load */
});

Thứ Năm, 23 tháng 4, 2009

ob_start()

<?php
ob_start();
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2">Tư vấn - Chăm sóc khách hàng</th>
</tr>
<tr>
<th>Họ tên: </th><td><?=$_POST['hoten']?></td>
</tr>
<tr>
<th>Địa chỉ: </th><td><?=$_POST['diachi']?></td>
</tr>
<tr>
<th>Email: </th><td><?=$_POST['email']?></td>
</tr>
<tr>
<th>Công ty: </th><td><?=$_POST['congty']?></td>
</tr>
<tr>
<th>Điện thoại: </th><td><?=$_POST['dienthoai']?></td>
</tr>
<tr>
<th>Tiêu đề: </th><td><?=$_POST['tieude']?></td>
</tr>
<tr>
<th>Nội dung: </th><td><?=$_POST['noidung']?></td>
</tr>
</table>
<?php
$buffer = ob_get_contents();
ob_end_clean();
?>

Thứ Tư, 15 tháng 4, 2009

Mở rộng quan hệ, mở lối thành công

From: http://advice.vietnamworks.com.vn/vi/print/548

Bạn rất ngại tham gia những cuộc gặp gỡ? Bạn cảm thấy khó khăn trong việc xây dựng các mối quan hệ xã hội?

Xây dựng mối quan hệ xã hội không có nghĩa là ngay lập tức hỏi thăm ai đó về cơ hội việc làm tại các ngày hội nghề nghiệp. Theo nghĩa chính xác nhất của từ này, xây dựng quan hệ xã hội chính là kết bạn và giao tiếp.

Gia đình, bạn bè, hàng xóm, đồng nghiệp cũ và mới đều là những nhân tố trong mạng lưới quan hệ xã hội của bạn. Tương tự cho bất cứ đối tượng nào bạn đang có quan hệ và thực sự quan tâm về họ.

Sự quan tâm – Chìa khóa để xây dựng quan hệ
Để có một mối quan hệ xã hội tốt, bạn phải là người biết quan tâm đến người khác. Sự quan tâm này có thể được thể hiện bằng nhiều cách khác nhau. Chẳng hạn, bạn nhớ ngày sinh nhật, những ngày kỷ niệm quan trọng khác của bạn bè, thể hiện sự cảm kích với những thành công bạn bè đạt được hay gửi thư cảm ơn họ vì đã giới thiệu bạn với ai hoặc giúp bạn việc gì.

Ngoài ra, bạn cần giữ liên lạc thường xuyên với bạn bè qua email, điện thoại và các buổi họp mặt thân mật. Mỗi tuần, bạn nên đặt mục tiêu gửi email hỏi thăm cho một người bạn quen (hoặc một người bạn muốn thiết lập quan hệ) và gọi điện ít nhất một lần cho một người bạn khác. Ngoài ra, hãy hẹn bạn bè ăn trưa mỗi tháng ít nhất một lần, hoặc chỉ đơn giản là uống cà phê. Nếu bạn không quen với những việc này, hãy ưu tiên ghi chúng vào danh sách những việc cần làm để dễ nhớ.

Hãy là người khởi xướng các hoạt động!
Một cách tuyệt vời để xây dựng các mối quan hệ xã hội là tham gia các sự kiện. Tuy nhiên, bạn hãy rủ mọi người tham gia những hoạt động vui chơi thân mật, hơn là tham dự các sự kiện mang tính trang trọng nhưng vô bổ.

Bạn có thể thành lập câu lạc bộ những người mê đọc sách, thích nấu ăn hay một nhóm đi bộ trong công ty; cùng đồng nghiệp ăn trưa hoặc tổ chức một đi chơi toàn công ty. Bạn cũng có thể rủ bạn bè đến nhà chơi, ăn tiệc tối hay tiệc nướng ngoài trời. Hãy khuyến khích mỗi người khách đến dự tiệc đi cùng với một người bạn mới. Việc khởi xướng những hoạt động tập thể như thế sẽ giúp bạn thiết lập quan hệ xã hội một cách dễ dàng mà không kém phần vui nhộn.

Chủ động kết nối với những người “đồng điệu”
Việc tích cực tham gia các hoạt động cũng quan trọng như khởi xướng. Tận dụng sở thích của bản thân cũng là một cách để mở rộng các mối quan hệ [2]. Chẳng hạn, nếu thích chơi golf, bạn đừng rủ người quen đi cùng mà hãy đến sân một mình rồi kiếm 3 người lạ để mời họ cùng chơi. Mỗi lần như vậy, bạn lại có thêm 3 người bạn mới. Nếu thích làm đồ gốm hoặc học ngôn ngữ ký hiệu (sign language), bạn hãy tham gia một khóa học sau giờ làm việc để có có hội tiếp xúc với những người “đồng điệu”. Chắc chắn sau khóa học, bạn sẽ kết bạn được với ít nhất một hay hai người.

Ngoài ra, rèn luyện thân thể tại các trung tâm thể dục hoặc tham gia vào các hoạt động chính trị - xã hội ở địa phương cũng là những cách lý tưởng khác để giao tiếp và kết bạn.

Trở thành “cầu nối” đáng tin cậy
Một trong những cách hay nhất để trở thành một người bạn tốt và một người xã giao giỏi là trở thành “cầu nối” của các mối quan hệ. Thay vì chỉ chú tâm vào việc những người quen và bạn bè có thể giúp bạn ra sao, hãy suy nghĩ xem bạn có thể giúp họ như thế nào. Chú ý khi ai đó nói với bạn rằng họ đang muốn mở rộng hoạt động kinh doanh sang một ngành nào đó hoặc họ đang tìm kiếm nhân sự với những kỹ năng chuyên sâu. Sau đó, bạn hãy nhớ lại xem có ai bạn quen có thể giúp họ không? Có ai thân với bạn có thể nắm bắt được cơ hội này không?

Trở thành cầu nối như thế, có thể bạn sẽ không thấy được lợi ích ngay tức thì cho bản thân và những tham vọng nghề nghiệp của bạn. Nhưng đến khi có việc cần, bạn sẽ thấy rõ giá trị của mạng lưới quan hệ xã hội [3]rộng.

(Theo Hotjobs.yahoo.com)

Thứ Ba, 14 tháng 4, 2009

Large File Downloads Issue Solved

//From: http://codeigniter.com/forums/viewthread/109798/

//CONTROLLER
// DOWNLOAD FILE
function download() {
// LOAD FILE SIZE PLUGIN
$this->load->plugin('filesize');
// GRAB FILE NAME
$file_name = $this->uri->segment(3);
// SET DIRECT PATH TO FILE
$file_path = "securefiles/".$file_namee;
// GRAB THE FILE SIZE
$file_size = get_filesize($file_path);
// CHOOSE WHICH DOWNLOAD METHOD BASED FILE SIZE
if ($file_size >= 45) {
// BEGIN DOWNLOAD
force_download($file_name, $file_path, 'large');
} else {
// READ FILE CONTENTS
$file_data = file_get_contents("securefiles/".$file_name);
// BEGIN DOWNLOAD
force_download($file_name, $file_data, 'small');
}
}

//DOWNLOAD HELPER PORTION MODIFIED
//Added Parameter: $type - Line 44
function force_download($filename = '', $data = '', $type = '')
//Added IF / ELSE statement - Line 75
// Generate the server headers
if ($type == 'small')
{
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: ".strlen($data));
}
else
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".strlen($data));
}
} else {
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
//header("Content-Length: ".strlen($data));
readfile($data);
}
else
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
//header("Content-Length: ".strlen($data));
readfile($data);
}
}
?>

A Base Model Template

class MY_Model extends Model
{
var $use_dbconfig = 'default';
var
$id = null;
var
$data = array();
var
$table;
var
$primary_key = 'id';
var
$fields = array();
var
$__insert_id = null;
var
$__num_rows = null;
var
$__affected_rows = null;
var
$return_array = TRUE;
var
$debug = FALSE;
var
$queries = array();
var
$_parent_name = '';

function
MY_Model()
{
parent
::Model();

$this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );

// We don't want to assign the model object to itself when using the
// assign_libraries function below so we'll grab the name of the model parent
$this->_parent_name = ucfirst(get_class($this));

log_message('debug', "Model Class Initialized");
}

/**
* Assign Libraries
*
* Creates local references to all currently instantiated objects
* so that any syntax that can be legally used in a controller
* can be used within models.
*
* @access private
*/
function _assign_libraries($use_reference = TRUE)
{
$CI
=& get_instance();
foreach (
array_keys(get_object_vars($CI)) as $key)
{
if ( ! isset($this->$key) AND $key != $this->_parent_name)
{
// In some cases using references can cause
// problems so we'll conditionally use them
if ($use_reference == TRUE)
{
// Needed to prevent reference errors with some configurations
$this->$key = '';
$this->$key =& $CI->$key;
}
else
{
$this
->$key = $CI->$key;
}
}
}
}

/**
* Load the associated database table.
*
* @author md emran hasan
* @access public
*/

function load_table($table, $config = 'default')
{
if ($this->debug) log_message('debug', "Loading model table: $table");

$this->table = $table;
$this->use_dbconfig = $config;

$this->load->database($config);
$this->fields = $this->db->list_fields($table);

if (
$this->debug)
{
log_message
('debug', "Successfull Loaded model table: $table");
}
}

/**
* Returns a resultset array with specified fields from database matching given conditions.
*
* @author md emran hasan
* @return query result either in array or in object based on model config
* @access public
*/

function find_all($conditions = NULL, $fields = '*', $order = NULL, $start = 0, $limit = NULL)
{
if ($conditions != NULL)
{
$this
->db->where($conditions);
}

if ($fields != NULL)
{
$this
->db->select($fields, FALSE);
}

if ($order != NULL)
{
$this
->db->orderby($order);
}

if ($limit != NULL)
{
$this
->db->limit($limit, $start);
}

$query
= $this->db->get($this->table);
$this->__num_rows = $query->num_rows();

if (
$this->debug)
{
$this
->queries[] = $this->db->last_query();
}

return ($this->return_array) ? $query->result_array() : $query->result();
}

/**
* Return a single row as a resultset array with specified fields from database matching given conditions.
*
* @author md emran hasan
* @return single row either in array or in object based on model config
* @access public
*/

function find($conditions = NULL, $fields = '*', $order = 'id ASC')
{
$data
= $this->find_all($conditions, $fields, $order, 0, 1);

if (
$data)
{
return $data[0];
}
else
{
return false;
}
}

/**
* Returns contents of a field in a query matching given conditions.
*
* @author md emran hasan
* @return string the value of the field specified of the first row
* @access public
*/

function field($conditions = null, $name, $fields = '*', $order = 'id ASC')
{
$data
= $this->find_all($conditions, $fields, $order, 0, 1);

if (
$data)
{
$row
= $data[0];

if (isset(
$row[$name]))
{
return $row[$name];
}
else
{
return false;
}
}
else
{
return false;
}

}

/**
* Returns number of rows matching given SQL condition.
*
* @author md emran hasan
* @return integer the number of records returned by the condition
* @access public
*/

function find_count($conditions = null)
{
$data
= $this->find_all($conditions, 'COUNT(*) AS count', null, 0, 1);

if (
$data)
{
return $data[0]['count'];
}
else
{
return false;
}
}

/**
* Returns a key value pair array from database matching given conditions.
*
* Example use: generateList(null, '', 0. 10, 'id', 'username');
* Returns: array('10' => 'emran', '11' => 'hasan')
*
* @author md emran hasan
* @return array a list of key val ue pairs given criteria
* @access public
*/

function generate_list($conditions = null, $order = 'id ASC', $start = 0, $limit = NULL, $key = null, $value = null, $first_key = '-1', $first_value = 'Inget valt')
{
$data
= $this->find_all($conditions, "$key, $value", $order, $start, $limit);

if (
$data)
{

if($first_key != NULL)
{
$keys[]
= $first_key;
$vals[] = $first_value;
}

foreach ($data as $row)
{
$keys[]
= ($this->return_array) ? $row[$key] : $row->$key;
$vals[] = ($this->return_array) ? $row[$value] : $row->$value;
}

if (!empty($keys) && !empty($vals))
{
$return
= array_combine($keys, $vals);
return
$return;
}
}
else
{
return false;
}
}

/**
* Returns an array of the values of a specific column from database matching given conditions.
*
* Example use: generateSingleArray(null, 'name');
*
* @author md emran hasan
* @return array a list of key value pairs given criteria
* @access public
*/

function generate_single_array($conditions = null, $field = null, $order = 'id ASC', $start = 0, $limit = NULL)
{
$data
= $this->find_all($conditions, "$field", $order, $start, $limit);

if (
$data)
{
foreach ($data as $row)
{
$arr[]
= ($this->return_array) ? $row[$field] : $row->$field;
}

return $arr;
}
else
{
return false;
}
}

/**
* Initializes the model for writing a new record.
*
* @author md emran hasan
* @return boolean True
* @access public
*/

function create()
{
$this
->id = false;
unset (
$this->data);

$this->data = array();
return
true;
}

/**
* Returns a list of fields from the database and saves in the model
*
* @author md emran hasan
* @return array Array of database fields
* @access public
*/

function read($id = null, $fields = null)
{
if ($id != null)
{
$this
->id = $id;
}

$id
= $this->id;

if (
$this->id !== null && $this->id !== false)
{
$this
->data = $this->find($this->primary_key . ' = ' . $id, $fields);
return
$this->data;
}
else
{
return false;
}
}

/**
* Inserts a new record in the database.
*
* @author md emran hasan
* @return boolean success
* @access public
*/

function insert($data = null)
{
if ($data == null)
{
return FALSE;
}

$this
->data = $data;
$this->data['create_date'] = date("Y-m-d H:i:s");

foreach (
$this->data as $key => $value)
{
if (array_search($key, $this->fields) === FALSE)
{
unset($this->data[$key]);
}
}

$this
->db->insert($this->table, $this->data);

if (
$this->debug)
{
$this
->queries[] = $this->db->last_query();
}

$this
->__insert_id = $this->db->insert_id();
return
$this->__insert_id;
}

/**
* Saves model data to the database.
*
* @author md emran hasan
* @return boolean success
* @access public
*/

function save($data = null, $id = null, $xss = TRUE)
{
if ($data)
{
$this
->data = $data;
}

foreach ($this->data as $key => $value)
{

if (array_search($key, $this->fields) === FALSE)
{
unset($this->data[$key]);
}
}

if($xss)
{
$this
->data = $this->input->xss_clean($this->data);
}

if ($id != null)
{
$this
->id = $id;
}

$id
= $this->id;

if (
$this->id !== null && $this->id !== false)
{
$this
->db->where($this->primary_key, $id);
$this->db->update($this->table, $this->data);

if (
$this->debug)
{
$this
->queries[] = $this->db->last_query();
}

$this
->__affected_rows = $this->db->affected_rows();
return
$this->id;
}
else
{
$this
->db->insert($this->table, $this->data);

if (
$this->debug)
{
$this
->queries[] = $this->db->last_query();
}

$this
->__insert_id = $this->db->insert_id();
return
$this->__insert_id;
}
}

/**
* Removes record for given id. If no id is given, the current id is used. Returns true on success.
*
* @author md emran hasan
* @return boolean True on success
* @access public
*/

function remove($id = null)
{
if ($id != null)
{
$this
->id = $id;
}

$id
= $this->id;

if (
$this->id !== null && $this->id !== false)
{
if ($this->db->delete($this->table, array($this->primary_key => $id)))
{
$this
->id = null;
$this->data = array();

if (
$this->debug)
{
$this
->queries[] = $this->db->last_query();
}

return true;
}
else
{
return false;
}
}
else
{
return false;
}
}

/**
* Returns a resultset for given SQL statement. Generic SQL queries should be made with this method.
*
* @author md emran hasan
* @return array Resultset
* @access public
*/

function query($sql)
{
$ret
= $this->db->query($sql);

if (
$this->debug)
{
$this
->queries[] = $this->db->last_query();
}

return $ret;
}

/**
* Returns the last query that was run (the query string, not the result).
*
* @author md emran hasan
* @return string SQL statement
* @access public
*/

function last_query()
{
return $this->db->last_query();
}

/**
* Returns the list of all queries peformed (if debug is TRUE)
*
* @author md emran hasan
* @return array list of SQL statements
* @access public
*/

function debug_queries()
{
$queries
= array_reverse($this->queries);
return
$queries;
}

/**
* This function simplifies the process of writing database inserts. It returns a correctly formatted SQL insert string.
*
* @author md emran hasan
* @return string SQL statement
* @access public
*/

function insert_string($data)
{
return $this->db->insert_string($this->table, $data);
}

/**
* Returns the current record's ID.
*
* @author md emran hasan
* @return integer The ID of the current record
* @access public
*/

function get_id()
{
return $this->id;
}

/**
* Returns the ID of the last record this Model inserted.
*
* @author md emran hasan
* @return int
* @access public
*/

function get_insert_id()
{
return $this->__insert_id;
}

/**
* Returns the number of rows returned from the last query.
*
* @author md emran hasan
* @return int
* @access public
*/

function get_num_rows()
{
return $this->__num_rows;
}

/**
* Returns the number of rows affected by the last query
*
* @author md emran hasan
* @return int
* @access public
*/

function get_affected_rows()
{
return $this->__affected_rows;
}
}


mod rewrite

From: http://codeigniter.com/wiki/mod_rewrite/

This article explains how to take away “index.php” from your CI application URLs. However, it does NOT remove the need for Index.php, which is the CI front controller i.e. even though Index.php will not appear in the URL, it still needs to be present at the top level of your site (above the /system/ directory). To quote the User Guide,

You can easily remove this file by using a .htaccess file with some simple rules.

You need to perform the following steps to get this working:

1. Create a .htaccess file to configure the rewrite engine

2. Set $config[‘index_page’] to an empty string

3. Make sure your apache uses the mod_rewrite module

4. Make sure apache is configured to accept needed .htaccess directives

5. Restart apache and test

1. Create your .htaccess file

Create a new file named .htaccess and put it in your web directory

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase
/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php?/$1 [L]
< /IfModule>

<
IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
< /IfModule>

The above configuration behaves as follows:

1. Checks to see if someone has entered a URL starting with “system”, all requests like this get routed to index.php, this is a security feature that removes the possibility of anyone directly accessing your system folder. You can use the same syntax to hide other folders inside your root if you want.

2. If the URL doesn’t start with “system”, the web server will check to see if there is a corresponding physical resource matching the URL, such as an image, script file, or directory.

3. If such a resource exists, that resource is returned by the webserver with no rewriting performed. If no such resource exists the url is rewritten to index.php (passed to codeigniter)

Notes for Windows users:
To create this file you must open Command Prompt and type:
copy con .htaccess [Enter]
[Press CTRL + Z]
A blank .htaccess file will be created. Now you can edit it using Notepad or your favorite text editor and copy the script above.

Note: Most Windows editors will assume that you are attempting to save an .htaccess file as a file with an extension and no filename. The Crimson Editor can be used to create and save .htaccess files and other files that have no filename.

Note: If your site is placed in subfolder specify the path in the “RewriteBase /subfolder/” line.

2. Set $config[‘index_page’] to an empty string

Open your

system/application/config/config.php

and find the line that assigns $config[‘index_page’] a value, usually:

$config['index_page'] = "index.php";

and change it to:

$config['index_page'] = '';

Save the file.

3. Make sure your apache has mod_rewrite activated

This means that the apache must be configured to load the mod_rewrite module (or it might have it compiled-in). For module inclusion, usually you have to look for a line like this in httpd.conf or a file loaded by it (hint: use some quick file search utility to grep files with lines containing ‘rewrite’ string):

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

If you’re running Apache2 type

a2enmod
in the console and when prompted
rewrite

to enable mod_rewrite.

On a Windows machine this line might look this way:

LoadModule rewrite_module modules/mod_rewrite.so

If it is commented out (# in front), make sure to uncomment it and save the file. Checking if the corresponding module exists may be a good idea as well (but it usually does).

4. Make sure apache accepts needed .htaccess directives

This means that apache is explicitly configured to allow .htaccess files to override those directives that you use in your .htaccess file from step 1. above.

It seems to be sufficient if you add these two lines to your section where you configure the document root for your CI application:

<Directory "/some/absolute/path/htdocs">
...
Options FollowSymLinks
AllowOverride FileInfo
...
< /
Directory>

There might be other Options listed, just make sure you have FollowSymLinks as well.

Should you get a 500 Internal Server Error, try the following syntax:

<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow
,deny
Allow from all
< /Directory>

5. Restart apache and test your application

Works? Congratulations!

Doesn’t work? Ehrrr… well, do not give up; equip yourself with patience, double check all steps above and if it still does not work, post on the forum giving all details of your setup.

How does URL rewriting work?

<IfModule mod_rewrite.c>
...
< /
IfModule>

Do what is inside only if Apache has the mod_rewrite feature (by in place compilation, or loaded module).

RewriteEngine On

Activate the URL rewriting engine, if not already done (in main Apache configuration file.

RewriteBase /

Define the part of the URL that won’t change nor be used for rewriting. In fact, this part will be removed before processing, and prepended after processing. This’s a good way to use subfolder-independent rewrite rules. For example, if your CodeIgniter index.php is placed in a virtual host directory, like /tests/, set RewriteBase to /tests/.

RewriteCond %{REQUEST_FILENAME} !-f

Condition to meet for RewriteRule activation. Here, we test if the requested filename does not exist.

RewriteCond %{REQUEST_FILENAME} !-d

Same as above, but we test for directory existence.

RewriteRule ^(.*)$ index.php/$1 [L]

If RewriteCond conditions are met, this rule will be applied. It inserts index.php before the requested URI. The $1 represents the part of string enclosed by parentheses in left expression. The [L] means that this rule is the last one if rule is applied (thus stopping rewriting).

Configuring mod_rewrite in the httpd.conf file

The Apache mod_rewrite docs say

While URL manipulations in per-server context are really fast and efficient, per-directory rewrites are slow and inefficient…

. If you have access to your httpd.conf file, you’ll have better performance if you configure the rewrite rules in there.

You can add something like this to your httpd.conf:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond
%{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
< /IfModule>

Configuring mod_rewrite and virtual hosting with Apache 2.2

<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot
/path/to/ci/directory
<Directory /path/to/ci/directory>
RewriteEngine On
RewriteBase
/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php/$1 [L]
< /Directory>
< /
VirtualHost>