Linux

URL rewriting and add www to .htaccess for hosting multiple domain or multi sites

Adding the www to URL in .htaccess for hosting multiple domain or multisites and handle www issue for canonical URLs.
    ##Adding the www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
    RewriteRule ^(.*)$ "http://www.%1/$1" [L,R=301]

The other way around you can removing the www from URL.

Remove www and rewrite URL for multi-sites or subdomains in .htaccess

If you are running a Multisites or Subdomains sites this .htaccess RewriteRule code might come in handy specially for purpose of SEO. You can clean up your URL from http://www.yourdomain.com to http://yourdomain.com and remove the “www” with 301 redirect to non-www.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

If you want to add the www to URLs check this out.

Convert Linux/Unix timestamp to human readable format in PHP

This functin will help to convert the Linux/Unix timestamp to human readable format:

<?php
function unix_timestamp_to_human ($timestamp ""$format 'D d M Y - H:i:s')
{
    if (empty(
$timestamp) || ! is_numeric($timestamp)) $timestamp time();
    return (
$timestamp) ? date($format$timestamp) : date($format$timestamp);
}

$unix_time "1251208071";

echo 
unix_timestamp_to_human($unix_time); //Return: Tue 25 Aug 2009 - 14:47:51 
?>

How to find file or folder location in Linux/Unix usnig bash command line

Use this grep commend

locate apache | egrep "\/apache$"

Example:

[myserver]$: locate apache | egrep "\/apache$"
[myserver]$: /usr/local/dh/apache