How to setup Scheduled Task on Windows XP

June 23rd, 2010

You have to set up scheduled task to run periodic tasks, such as fetching of emails into Support Center, generating knowledge base files or sending notifications.

Steps to create scheduled task on windows XP:

1. open Control Panel

2. Open Scheduled Tasks

3. Click on icon Add Scheduled Task – wizard will be opened


4. Follow wizard to next step



5. Click Browse, locate php.exe on your file system and click Open. Than continue to next step.


6. Select name for your scheduled task and select Daily period


7. Select, when should your task be executed (Every Day)


8. Select password and user under which will be task executed


9. At the end of wizard select checkbox: Open advanced properties for this task when I click Finish


10. Add to path of php.exe also full path to your jobs.php located in server directory of Support Center installation folder


11. Select second Tab Schedule


12. Click on button “Advanced…“ and select checkbox Repeat task and define, that task should be repeated every minute in duration 24 hours

13. Click Ok and open Tab Settings and define following settings:


14. Click Ok and review your username and password


You are ready, task was scheduled

Advice: Setting up Scheduled Task properly is important. Without periodical execution of jobs.php there will be no emails loaded by the system !

Reverse Proxy with URL Rewrite v2 and Application Request Routing

June 17th, 2010

This walkthrough will guide you through how to use URL Rewrite Module and Application Request Routing (ARR) to implement a reverse proxy server for multiple back-end applications.
Prerequisites

To run this walkthrough, you must have the following:

1. IIS 7 with ASP.NET role service enabled.
2. URL Rewrite Module installed (version 2.0 is required if you want to complete the part about response rewriting)
3. Application Request Routing version 1.0 or version 2.0 installed

Introduction

By using URL Rewrite Module and Application Request Routing you can implement complex and flexible load balancing and reverse proxy configurations. A very common reverse proxy scenario is to make available several internal web applications over the Internet. An Internet-accessible Web server is used as a reverse-proxy server that receives Web requests and then forwards them to several intranet applications for processing: The following figure illustrates a typical configuration for a reverse-proxy scenario:

Assuming that the ARR server has a domain name http://contoso.com, each web application can be accessed by using these URLs:

* http://contoso.com/webmail/
* http://contoso.com/payroll/

When a request is made to http://contoso.com/webmail/default.aspx, ARR forwards these requests to an internal server using the URL http://webmail/default.aspx. Similarly, requests to http://contoso.com/payroll/ are forwarded to http://payroll/default.aspx.

In addition, if internal application inserts links into its response HTML that link to elsewhere in those applications, those links should be modified before the response is returned to the client. For example, a page from http://webmail/default.aspx might contain a link like this:
link

Then ARR server should change this link to the following:
link
Creating the Example Web Sites

For simplicity, the reverse-proxy scenario you will work with in this walkthrough will be implemented on a single server, with the IIS “Default Web Site” acting as a reverse-proxy site and webmail and payroll applications hosted in separate IIS web sites on the same server.

To create the example Web sites:

1. Create two folders called “webmail” and “payroll” in the following folder:

%SystemDrive%\inetpub\ folder.
2. Create two IIS web sites called “webmail” and “payroll” that point to corresponding folders under %SystemDrive%\inetpub\. Use different IP ports for each site.
You can use the following commands to create the sites:

%windir%\System32\inetsrv\appcmd.exe add site /name:”webmail” /bindings:http/*:8081: /physicalPath:”%SystemDrive%\inetpub\webmail

%windir%\System32\inetsrv\appcmd.exe add site /name:”payroll” /bindings:http/*:8082: /physicalPath:”%SystemDrive%\inetpub\payroll
3. Create a file named default.aspx in the following folder:

%SystemDrive%\inetpub\webmail

4. Copy the following ASP.NET markup, paste it into the file, and save the file:

<%@ Page Language="C#" %>




Reverse Proxy Test Page – WebMail Application

Requested URL path is <%= Request.ServerVariables["SCRIPT_NAME"] %>

“>Here is the link to this page.



5. Create a file named default.aspx in the following folder:

%SystemDrive%\inetpub\payroll
6. Copy the following ASP.NET markup, paste it into the file, and save the file:

<%@ Page Language="C#" %>




Reverse Proxy Test Page – Payroll Application

Requested URL path is <%= Request.ServerVariables["SCRIPT_NAME"] %>

“>Here is the link to this page.



7. To make sure that sites are working correctly, open a Web browse and request the following URLs:

http://localhost:8081/default.aspx

http://localhost:8082/default.aspx

Configuring Rules for the Reverse Proxy

In this section of the walkthrough, you will configure reverse proxy functionality to work with the example Web sites that you have created.
Enabling Reverse Proxy functionality

Reverse Proxy functionality is disabled by default, so you must begin by enabling it.

1. Open IIS Manager
2. Select a server node in the tree view on the left hand side and then click on the “Application Request Routing” feature:

3. Check the “Enable Proxy” check box. Leave the default values for all the other settings on this page:

Creating a rule for webmail application

You will create two rewrite rules:

* A rewrite rule that will proxy any request to webmail application at http://localhost:8081/ as long as requested URL path starts with “webmail”.
* A rewrite rule that will proxy any request to payroll application at http://localhost:8082/ as long as requested URL path starts with “payroll”.

To add the reverse proxy rewrite rules:

1. Open the web.config file located in the following location:

%SystemDrive%\inetpub\wwwroot\
2. Under the /configuration/system.webServer element, add the following and then save the file:












For more information about creating rewrite rules, see Creating Rewrite Rules for the URL Rewrite Module.
Testing the reverse proxy functionality

Open a web browser and make a request to http://localhost/webmail/default.aspx. You should see the response from the webmail test page. Also, make a request to http://localhost/payroll/default.aspx. You should see the response from the payroll test page.

Notice that in both cases the link inside of the response points to http://localhost/default.aspx. If you click on this link it will result in 404 (File Not Found) response from the server. In next section you will learn how create an outbound rule to fix the links the response HTML generated by the application.
Configuring rules for response rewriting

This section of the documentation applies to the URL Rewrite Module Version 2.0 for IIS 7.

You will define an outbound rule that replaces all the links within the response HTML as follows:

will be replaced with:

(if the response came from webmail application)

and

(if the response came from payroll application)

WARNING: When response headers or the response content is modified by an outbound rewrite rule an extra caution should be taken to ensure that the text which gets inserted into the response does not contain any client side executable code, which can result in cross-site scripting vulnerabilities. This is especially important when rewrite rule uses un-trusted data, such as HTTP headers or the query string, to build the string that will be inserted into the HTTP response. In such cases the replacement string should be HTML encoded by using the HtmlEncode function, e.g:

To create the rule, follow these steps:

1. Go to IIS Manager
2. Select “Default Web Site”
3. In the Feature View click “URL Rewrite“
4. In the Actions pane on the right hand side click on “Add Rules…”. In the “Add Rules” dialog select the “Blank Rule” under the “Outbound Rules” category and click OK:

Now you must define the actual outbound rule. In the URL Rewrite Module 2.0, an outbound rewrite rule is defined by specifying the following information:

* Name of the rule.
* An optional precondition that controls whether this rule should be applied to a response.
* The pattern to use for matching the string in the response.
* An optional set of conditions.
* The action to perform if a pattern is matched and all condition checks succeeded.

Naming the rule

In the “Name” text box enter a name that will uniquely identify the rule, for example: ”Add application prefix”.
Defining a Precondition

A precondition is used to evaluate whether the outbound rules evaluation should be performed on a response. For example if a rule that modifies HTML content, only HTTP responses with content-type header set to “text/html” should be evaluated against this rule. Outbound rules evaluation and content rewriting is a CPU intensive operation that may negatively affect the performance of a web application. Therefore, use preconditions to narrow down the cases when outbound rules are applied.

Because the rule that you are creating should be applied only on HTML responses, you will define a precondition that checks whether the HTTP response header content-type is equial to “text/html”.

To define a precondition:

1. In the Pre-conditions list, select ““.
2. This will bring you to the Pre-condition editor dialog, where you will need to define the precondition. Specify the precondition settings as follows:
* Name: “IsHTML”
* Using: “Regular Expressions”
* Click “Add” to bring up the “Add condition” dialog. In this dialog specify:
o Condition input: “{RESPONSE_CONTENT_TYPE}”
o Check if input string: “Matches the pattern”
o Pattern: “^text/html”

3. Click OK to save the precondition and to return to the “Edit Rule” page.

Defining a matching scope

The outbound rewrite rule can operate on the content of an HTTP header or on the response body content. This rule needs to replace links in the response content so in the “Matching Scope” drop down list choose “Response”.
Defining a tag filter

Tag filters are used to scope the pattern matching to a certain HTML elements only, instead of evaluating the entire response against the rule’s pattern. Pattern matching is a very CPU-intensive operation and if an entire response is evaluated against a pattern, it can significantly slow down the Web application response time. Tag filters allow you to specify that the pattern matching should be applied only within the content of certain HTML tags, thus significantly reducing the amount of data that has to be evaluated against regular expression pattern.

To define a tag filter, expand the drop down list “Match the content within:” and then select and check the check box “A (href attribute)”.

This sets the rule to apply the pattern only to the value of the href attribute of the hyperlink, as in the following example:
Some link
Defining a pattern

In the “Pattern” text box enter the following string:
^/(.*)

This string is a regular expression that specifies that the pattern will match any URL path string that starts with “/” symbol.

Note the usage of parenthesis within the pattern. These parentheses create a capture group, which can be later referenced in the rule by using back-references.
Defining a condition

You need to change the links in the response HTML only if response is from the webmail or payroll application. To check that you will use a condition that analyzes the URL path requested by client. Also you will define a condition pattern that captures the application folder from the requested URL, so that rule could re-use that when rewriting the links in the response.

1. Expand the conditions group box.
2. Click “Add…” button to bring up the dialog box for defining conditions.
3. For “Condition input:” enter this string: “{URL}”. This configures URL rewrite module to use the URL path that was requested by web client.
4. In the drop down combo box select “Matches the pattern”.
5. In the “Pattern” textbox enter “^/(webmail|payroll)/.*”. This regular expression will be used to match the URL paths that start with either /webmail or /payrol. Also the parenthesis within the pattern will capture the part of the matched URL string, so that we can re-use when constructing the replacement URL.
6. Click OK to save the condition and return to the “Add Rule” UI.

Defining an action

Choose the “Rewrite” action type that is listed in the “Action” group box. In the “Value” text box, enter the following string:
/{C:1}/{R:1}

This string specifies the new value to which the link address should be rewritten. The {C:1} is a back-reference to the condition pattern capture group and it will be substituted with either “webmail” or “payroll” strings. The {R:1} is a back-reference to the rule pattern capture group and in this particular case it will be substituted with the original URL path that was used in the hyperlink.

Leave default values for all other settings. The “Edit Outbound Rule” property page should look like below:

Save the rule by clicking on “Apply” action on the right hand side.

To check the configuration of the rules that we have just created, open a web.config file located in %SystemDrive%\inetput\wwwroot\. In this file you should see the section that contains this rule definition:




















Testing the rule

To test that the rule correctly rewrites URLs in the response, open a Web browser and make a request to http://localhost/webmail/default.aspx or http://localhost/payroll/default.aspx. You should see that the outbound rewrite rule has changed the link within the HTML response:

Summary

In this walkthrough you have learned how to configure URL Rewrite Module and Application Request Routing to implement a reverse proxy scenario. Also you have learned how to use new outbound rewriting feature of URL Rewrite Module 2.0 to fix up the links in the applications’ responses before serving them to web client.

Note that when using reverse proxy it often is also required to rewrite the HTTP response headers. To learn how to use URL Rewrite Module 2.0 to modify the response HTTP header refer to Modifying HTTP Response Headers.

How to Add a Windows Live Messenger IM Control to a PHP Page

June 7th, 2010

Would you like to be able to interact with your site users more dynamically than through email?  You can add a Windows Live Messenger IM control to your page which will allow your site users to see when you are online and initiate a conversation with you. For example:

 

This control does not require visitors to have a Windows Live ID, they will be required to enter a CAPTCHA.  When you sign in to the Windows Live Messenger client application, the above web control displayed on your site will dynamically recognize that you are online and display your presence information.  Messages sent from the user will be directed to your client application as would a conversation initiated by one of your contacts. This functionality can be added to your web page with a few straightforward steps.

 

Step 1: Enable your online presence.

To do this, click the following link and sign in using your Windows Live ID.

http://settings.messenger.live.com/applications/WebSettings.aspx

Under ‘Manage your Messenger web settings, check the checkbox to allow anyone on the web to see your online presence.

Screen   shot of the Windows Live Messenger Web Settings page.

 

Then click on the Save button near the top of the page to save this setting.

 

Step 2: Generate the HTML required to display the IM control.

On the left side of the page, under the ‘Web Settings’ heading, click on the ‘Create HTML’ link.

 

From this page, you can decide how your presence should ‘look’.  You can choose to display a full IM control, a button or just an icon to alert users of your presence.  Any of these options will allow a user to initiate a conversation with you when you are online.  Choose a color for the theme of your control or button.  Additionally, if you choose to display the IM control, you can set the width and height. Once you have made your selections for style and appearance, notice that HTML has been generated at the bottom of the page.  This is the HTML you will need in order to display the control on your web page.  If you choose an icon to display your presence, then the HTML will contain a link, but if you choose the full control, then the HTML specifies an iFrame. 

 

Note that the [unique id] in red, in the above screenshot will be a hash unique to your account.

 

Step 3: Copy and paste the HTML into a page where you would like to display your presence.

 

 

That’s all!  Browse to your site and the page to which you added the control.  You are now ready to host conversations with your web site users.  The screenshot below shows the ‘orange’ theme applied to the full IM control.

 

 

How does it work?  When you gave consent for the Windows Live Messenger Service to display your presence information online, a unique id was made.  The generated HTML uses this id as a parameter which is then passed to the service and used to route messages from the IM control to your IM account.  Other parameters are specified in the query string for the theme and, if applicable, height and width, customizations.  The parameters are used to render the IM control, button or icon.

Download Solution Package From CodePlex Now

Skype status on the web

Integrate Windows Live Messenger into a PHP Site

June 7th, 2010

Before you get started, there are a couple of important prerequisites.

  • You must have a Windows Live ID to complete this tutorial.  If you don’t have one, get one here:

    https://signup.live.com/

  • You must have the following extensions enabled in your PHP configuration:
    • hash or mhash
    • mcrypt
    • curl

    To enable these extensions, browse to your PHP install and open PHP.ini at the root PHP directory.  Search for ‘mhash’ and look for a line that looks like this:

    ;extension=php_mhash.dll

    Remove the leading semicolon to enable the extension. For example:

    extension=php_mhash.dll

    Do the same for php_mcrypt.dll and php_curl.dll.  They will all be located in this same section of the PHP.ini file.  When you have enabled all three, save the file.  Assuming you have made these changes locally for testing in a local environment, once you deploy your Live Messenger Application, you’ll need to make the same changes to the PHP.ini file on your server.

Step 1: Download the Windows Live Messenger Web Toolkit samples.

There is a link to the download on the right side of the page, Download Messenger Samples.

http://dev.live.com/Messenger/

Extract the files and browse to the PHP directory located in the WebToolkit  > GettingStarted directory.  This code sample includes everything you need to include Windows Live Messenger in your web application; however, there is a small amount of configuration required.  Browse to the conf directory and open the settings.xml file.

settings.xml

Notice the appid, secret  and messengerSecret elements.  The values of these elements must be unique to you and your application.   In order to get these numbers, you will need to create a Windows Live Services account.  No worries, it’s free.

Step 2: Create a Windows Live Services Account

To create your account, go to the Azure Services Developer Portal (http://go.microsoft.com/fwlink/?LinkID=144070) and sign in using your Windows Live ID.  Once you are authenticated, you will see the following page:

Azure Live Services Home

Click on the ‘+ New Service’ link at the top right.  On the next page you have the option to create service components.  Under the Azure Services Platform section, click on ‘Live Services: Existing APIs’.

Create a new Service Component

The Create a Service Component page allows you to set service component properties.  Enter a service component label and description.  You can enter anything you want here; these are for your reference to identify your service components on the Azure Live Service Portal site. In the domain field, enter the domain name for your site. The login control uses Delegated Authentication and will verify that that the request to authenticate a user from your website originated from the domain you specify here. Then enter a return URL.  This is the page that users will be directed to after they have signed in to the Windows Live Messenger Service.

Service Component Properties

You are then directed to a page specific to your service component. You should see the application ID and secret key that have been assigned to you.  These are the values that need to be placed in the settings.xml file. 

ApplicationID and Secret Key

Copy and paste the Application ID to the appid element in the settings.xml file.  Also copy and paste the secret key from the Azure Live Service portal page into the secret element in the settings.xml file.  Save the file.

In addition to appid and secret key, the settings.xml also requires messengerSecret id (messenger application key). To get your messengerSecret id, browse to the following url after replacing {appid} with your appid.

https://consent.messenger.services.live.com/applicationsettings.aspx?appid={appid}

You will be directed to a page where you can see the messenger secret id (Messenger Application Key).

Messenger Secret Key

Copy and paste Messenger Application Key to the MessengerSecret element in settings.xml file. Save the file.

Step 3: How does it work?

The recommended way to provide Windows Live Messenger sign in functionality on a web site is by using the sign-in control.  The sign-in control requires that your site implement delegated authentication. Delegated authentication means that a site must request consent from a user and the user must grant consent to the application.  When consent has been granted, the application receives a consent token which is used to authenticate a user and log them in to Windows Live Messenger. Open index.php which is located at the root of the PHP directory using a code editing tool.  Take a look near the top of the page.  There are several things required to initialize the Windows Live Messenger application.

  • Notice the php includes: lib/settings.php and lib/windowslivelogin.php.   The settings.php file reads the settings.xml file where you added your application ID and secret key.  The windowslivelogin.php file contains, amongst other things, logic to perform delegated authentication and initialize the application. 
  • PHP Code Screenshot

     

  • A single line of PHP code creates an instance of the WindowsLiveLogin module using the application ID and secret that you set in the settings.xml file. 
  • PHP Code Screenshot

     

  • Look at the <html> tag.  There is an important namespace defined here for the UI controls.
  • PHP Code Screenshot

     

  • There is one Javascript file which needs to be included.  This file includes a ‘loader’ class which is used to load Windows Live Messenger Toolkit components.
  • PHP Code Screenshot

     

  • A Javascript call is made to load the Windows Live Messenger styles via the loader class.
  • PHP Code Screenshot

     

  • In the <body> tag of the HTML, a <msgr:app> element initializes the application.  There are a couple of important attributes of which to take note.
    • id : an id for your application.
    • application-verifier-token : this is a unique token created by a hash of your application id and the current timestamp.  It could also include an IP address.
    • token-url: the URL of the page containing logic to refresh / check the token.
    • privacy-url : a link to your site’s privacy policy
    • channel-url: this is provided with the sample and is necessary for cross domain communication between the Windows Live Service domain and your site.
  • PHP Code Screenshot

     Note that when using the sign-in control (which the sample does), both the privacy-url and the channel-url must be set.  A basic privacy page is included with the sample code, but if you already have a privacy policy on another page, simple change this URL to the existing page. Additionally, the channel page must be hosted on the same domain as the application.

    Also, there can only be one instance of the msgr:app control per page.

  • Lastly, there are tags for the profile, sign-in and tool bar controls.  The msgr:if control provides conditional logic but does not have a physical presence on the web page which is visible to the user.
  • PHP Code Screenshot

     

Step 4: Test the application.

Open the index.php file located at the root of the PHP directory in a web browser.  You should see the following: 

If you are working locally, then you will not be able to login because the domain name from which you are accessing Live Services does not match that which you specified in your Windows Live Services project created in step 2.

If the sign in page loads and looks as expected (similar the to screenshot above), then you are ready to deploy the application at which time you will be able to successfully sign in.

Step 5: Deploy the application.

Copy all of the files located in the PHP directory to a location on your web server where you would like to host the sample application.  If you enabled the hash or mhash, mcrypt and curl extensions in your PHP.ini file locally then you will need to make these changes on your server now.

When you browse to index.php, it should look similar to the following:

 

Download Solution Package From CodePlex Now

You can now sign in to Windows Live Messenger from this page.  Once you’ve signed in, the page displays your profile information which includes your display picture, status and personal message text.  Also look at the web toolbar at the bottom of the page.  From here you can view your contacts and initiate Live Messenger conversations as well as change your status or sign out. 

upload multiple files

June 6th, 2010

<?php
/*
*
* @ Multiple File upload script.
*
* @ Can do any number of file uploads
* @ Just set the variables below and away you go
*
* @ Author: Kevin Waterson
*
* @copywrite 2008 PHPRO.ORG
*
*/

error_reporting(E_ALL);

/*** the upload directory ***/
$upload_dir= './uploads';

/*** numver of files to upload ***/
$num_uploads = 5;

/*** maximum filesize allowed in bytes ***/
$max_file_size  = 51200;

/*** the maximum filesize from php.ini ***/
$ini_max = str_replace('M', '', ini_get('upload_max_filesize'));
$upload_max = $ini_max * 1024;

/*** a message for users ***/
$msg = 'Please select files for uploading';

/*** an array to hold messages ***/
$messages = array();

/*** check if a file has been submitted ***/
if(isset($_FILES['userfile']['tmp_name']))
{
/** loop through the array of files ***/
for($i=0; $i < count($_FILES['userfile']['tmp_name']);$i++)
{
// check if there is a file in the array
if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i]))
{
$messages[] = 'No file uploaded';
}
/*** check if the file is less then the max php.ini size ***/
elseif($_FILES['userfile']['size'][$i] > $upload_max)
{
$messages[] = "File size exceeds $upload_max php.ini limit";
}
// check the file is less than the maximum file size
elseif($_FILES['userfile']['size'][$i] > $max_file_size)
{
$messages[] = "File size exceeds $max_file_size limit";
}
else
{
// copy the file to the specified dir
if(@copy($_FILES['userfile']['tmp_name'][$i],$upload_dir.'/'.$_FILES['userfile']['name'][$i]))
{
/*** give praise and thanks to the php gods ***/
$messages[] = $_FILES['userfile']['name'][$i].' uploaded';
}
else
{
/*** an error message ***/
$messages[] = 'Uploading '.$_FILES['userfile']['name'][$i].' Failed';
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Multiple File Upload</title>
</head>

<body>

<h3><?php echo $msg; ?></h3>
<p>
<?php
if(sizeof($messages) != 0)
{
foreach($messages as $err)
{
echo $err.'<br />';
}
}
?>
</p>
<form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
<?php
$num = 0;
while($num < $num_uploads)
{
echo '<div><input name="userfile[]" type="file" /></div>';
$num++;
}
?>

<input type="submit" value="Upload" />
</form>

</body>
</html>

automatically mysql backup

May 25th, 2010

MySQL is one of the most popular open source database management system for the development of interactive Websites.

If your site stores its sensitive data in a MySQL database, you will most definitely want to backup that information so that it can be restored in case of any disaster (we all have been there).

There are several ways to backup MySQL data. In this article we’ll look at how to backup your databases using different methods, we will also learn how to achieve an automatic backup solution to make the process easier. Starting with the mysqldump utility that comes with MySQL, we will review several examples using mysqldump, including the backup of your database to a file, another server, and even a compressed gzip file and send it to your email.

1. Automatically backup mysql database to Amazon S3

Mysql Backup1 in 10 Ways to Automatically & Manually Backup  MySQL Database

Many of users use Amazon S3 to backup their mysql databases. Here is an automated script which does this task of taking the backup of a mysql database and then moving it to the Amazon S3.

2. How to Backup MySQL Database automatically (for Linux users)

  1. 15 2 * * * root mysqldump -u root -pPASSWORD –all-databases | gzip > /mnt/disk2/database_`data ‘ %m-%d-%Y’`.sql.gz

This post will show you how to backup MySQL Database automatically if you are a linux user. You can use cron to backup your MySQL database automatically.”cron” is a time-based scheduling utility in Unix/Linux
operating system.

3. Backup your MySQL databases automatically with AutoMySQLBackup

AutoMySQLBackup has some great features to: backup a single database, multiple databases, or all the databases on the server; each database is saved in a separate file that can be compressed (with gzip or bzip2); it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.).

4. Backing Up With MySQLDump

  1. mysqldump —user [user name] —password=[password]
  2. [database name] > [dump file]

In this article we’ll look at how to backup our databases using the mysqldump utility that comes with MySQL. Several examples will be reviewed using mysqldump, including the backup of your database to a file,
another server, and even a compressed gzip file.

5. Backup Your Database into an XML File Using PHP

  1. mysqldump —user [user name] —password=[password]
  2. [database name] > [dump file]

Here’s a PHP snippet that outputs your database as XML. XML isn’t the easiest format to restore a table but it can be easier to read.

6. How to – Using PHP To Backup MySQL Database

Execute a database backup query from PHP file. Below is an example of using SELECT INTO OUTFILE query for creating table backup:

  1. <?php
  2. include ‘config.php’;
  3. include ‘opendb.php’;
  4. $tableName = ‘mypet’;
  5. $backupFile = ‘backup/mypet.sql’;
  6. $query = “SELECT * INTO OUTFILE ’$backupFile’ FROM $tableName”;
  7. $result = mysql_query($query);
  8. include ‘closedb.php’;
  9. ?>

To restore the backup you just need to run LOAD DATA INFILE query like this :

  1. <?php
  2. include ‘config.php’;
  3. include ‘opendb.php’;
  4. $tableName = ‘mypet’;
  5. $backupFile = ‘mypet.sql’;
  6. $query = “LOAD DATA INFILE ’backupFile’ INTO TABLE $tableName”;
  7. $result = mysql_query($query);
  8. include ‘closedb.php’;
  9. ?>

7. Backup MySQL Database Via SSH

A simple solution to backup your large MySQL databases through SSH. You will need to enable shell access inside your Plesk control panel and use a utility such as PuTTY to log into your server via SSH.

8. How to e-mail yourself an automatic backup of your MySQL database table with PHP

This script will send an e-mail to you with an .sql file attached, thus enabling you to back up specific tables easily. You could even set up an e-mail account just to receive these backups…

9. Ubuntu Linux Backup MySQL server Shell Script

If you have a dedicated VPS server running Ubuntu Linux. Here is how to backup all your mysql server databases to your ftp server

10. How to backup MySQL databases, web server files to a FTP server automatically

This is a simple backup solution for people who run their own web server and MySQL server on a dedicated box or VPS. The main advantage of using FTP or NAS backup is a protection from data loss.First you will need to backup each database with mysqldump command, Automating tasks of backup with tar, Setup a cron job and generate FTP backup script.

  1. $ mysqldump -u root -h localhost -pmypassword faqs | gzip -9 > faqs-db.sql.gz

11. MySQL Export: How to backup your MySQL database?

Mysql Backup2 in 10 Ways to Automatically & Manually Backup  MySQL Database

You can easily create a dump file(export/backup) of a database used by your account. In order to do so you should access the phpMyAdmin tool available in your cPanel.

Worth Reading

- 10 things you need to know about backup solutions for MySQL

Are you using someone else’s backup solution for your MySQL data? Do you care a lot about your data? Are you sure you’re getting a reliable, recoverable backup that’ll work for your business and your application, and won’t impact your critical processes while it runs? Here are ten questions you need to be able to answer.

MySQL is one of the most popular open source database management system for the development of interactive Websites.

If your site stores its sensitive data in a MySQL database, you will most definitely want to backup that information so that it can be restored in case of any disaster (we all have been there).

There are several ways to backup MySQL data. In this article we’ll look at how to backup your databases using different methods, we will also learn how to achieve an automatic backup solution to make the process easier. Starting with the mysqldump utility that comes with MySQL, we will review several examples using mysqldump, including the backup of your database to a file, another server, and even a compressed gzip file and send it to your email.

1. Automatically backup mysql database to Amazon S3

Mysql Backup1 in 10 Ways to Automatically & Manually Backup  MySQL Database

Many of users use Amazon S3 to backup their mysql databases. Here is an automated script which does this task of taking the backup of a mysql database and then moving it to the Amazon S3.

2. How to Backup MySQL Database automatically (for Linux users)

  1. 15 2 * * * root mysqldump -u root -pPASSWORD –all-databases | gzip > /mnt/disk2/database_`data ‘ %m-%d-%Y’`.sql.gz

This post will show you how to backup MySQL Database automatically if you are a linux user. You can use cron to backup your MySQL database automatically.”cron” is a time-based scheduling utility in Unix/Linux
operating system.

3. Backup your MySQL databases automatically with AutoMySQLBackup

AutoMySQLBackup has some great features to: backup a single database, multiple databases, or all the databases on the server; each database is saved in a separate file that can be compressed (with gzip or bzip2); it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.).

4. Backing Up With MySQLDump

  1. mysqldump —user [user name] —password=[password]
  2. [database name] > [dump file]

In this article we’ll look at how to backup our databases using the mysqldump utility that comes with MySQL. Several examples will be reviewed using mysqldump, including the backup of your database to a file,
another server, and even a compressed gzip file.

5. Backup Your Database into an XML File Using PHP

  1. mysqldump —user [user name] —password=[password]
  2. [database name] > [dump file]

Here’s a PHP snippet that outputs your database as XML. XML isn’t the easiest format to restore a table but it can be easier to read.

6. How to – Using PHP To Backup MySQL Database

Execute a database backup query from PHP file. Below is an example of using SELECT INTO OUTFILE query for creating table backup:

  1. <?php
  2. include ‘config.php’;
  3. include ‘opendb.php’;
  4. $tableName = ‘mypet’;
  5. $backupFile = ‘backup/mypet.sql’;
  6. $query = “SELECT * INTO OUTFILE ’$backupFile’ FROM $tableName”;
  7. $result = mysql_query($query);
  8. include ‘closedb.php’;
  9. ?>

To restore the backup you just need to run LOAD DATA INFILE query like this :

  1. <?php
  2. include ‘config.php’;
  3. include ‘opendb.php’;
  4. $tableName = ‘mypet’;
  5. $backupFile = ‘mypet.sql’;
  6. $query = “LOAD DATA INFILE ’backupFile’ INTO TABLE $tableName”;
  7. $result = mysql_query($query);
  8. include ‘closedb.php’;
  9. ?>

7. Backup MySQL Database Via SSH

A simple solution to backup your large MySQL databases through SSH. You will need to enable shell access inside your Plesk control panel and use a utility such as PuTTY to log into your server via SSH.

8. How to e-mail yourself an automatic backup of your MySQL database table with PHP

This script will send an e-mail to you with an .sql file attached, thus enabling you to back up specific tables easily. You could even set up an e-mail account just to receive these backups…

9. Ubuntu Linux Backup MySQL server Shell Script

If you have a dedicated VPS server running Ubuntu Linux. Here is how to backup all your mysql server databases to your ftp server

10. How to backup MySQL databases, web server files to a FTP server automatically

This is a simple backup solution for people who run their own web server and MySQL server on a dedicated box or VPS. The main advantage of using FTP or NAS backup is a protection from data loss.First you will need to backup each database with mysqldump command, Automating tasks of backup with tar, Setup a cron job and generate FTP backup script.

  1. $ mysqldump -u root -h localhost -pmypassword faqs | gzip -9 > faqs-db.sql.gz

11. MySQL Export: How to backup your MySQL database?

Mysql Backup2 in 10 Ways to Automatically & Manually Backup  MySQL Database

You can easily create a dump file(export/backup) of a database used by your account. In order to do so you should access the phpMyAdmin tool available in your cPanel.

Worth Reading

- 10 things you need to know about backup solutions for MySQL

Are you using someone else’s backup solution for your MySQL data? Do you care a lot about your data? Are you sure you’re getting a reliable, recoverable backup that’ll work for your business and your application, and won’t impact your critical processes while it runs? Here are ten questions you need to be able to answer.

mod_rewrite tips and tricks using htaccess

May 25th, 2010

20+ .htaccess Hacks Every Web Developer Should Know About

Apache’s .htaccess(hypertext access) configuration file can be a very powerful tool in a web developer’s toolkit if used properly. It can be found in the webroot of your server and can be easily edited using any text editor. In this article I’m going to show you 20 .htaccess hacks and how to use them.

Before I start with this article I’d like to start by saying that abusing the .htaccess file will hurt the performance of your website. The .htaccess file should only be used if you have no other way to achieve certain things.

Make sure to back up your current .htaccess file before applying any of the following hacks.

1. Prevent Hotlinking

Tired of people using your bandwidth by putting the images hosted on your server on their website? Add the following code at the bottom of your .htaccess file to prevent hotlinking.

1 Options +FollowSymlinks
2 #Protect against hotlinking
3 RewriteEngine On
4 RewriteCond %{HTTP_REFERER} !^$
5 RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
6 RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/stop_stealing_bandwidth.gif[nc]

NOTE: The following article explains better methods to “prevent” hotlinking:
Link building secrets by Maurizio Petrone

2. Block All Requests From User Agents

It’s possible to block all unwanted user agents that might be potentially harmful or perhaps just to keep the server load as low as possible.

01 #Block bad bots
02 SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]
03 SetEnvIfNoCase user-Agent ^Java.* [NC,OR]
04 SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]
05 SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]
06 SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]
07 SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]
08 SetEnvIfNoCase user-Agent ^Zeus [NC]
09 <limit get="" post="" head="">
10 Order Allow,Deny
11 Allow from all
12 Deny from env=bad_bot
13 </limit>

3. Redirect Everyone Except Specified IPs

If for some reason you would want to deny everyone or allow only a specific group of IP addresses to access your website, add the following code to your .htaccess file:

1 ErrorDocument 403 http://www.domainname.com
2 Order deny,allow
3 Deny from all
4 Allow from 124.34.48.165
5 Allow from 102.54.68.123

4. SEO Friendly 301 Redirects

If you’ve transferred domain names or wish to redirect a specific page or pages without getting penalty from search engines such as Google, use the following code:

1 Redirect 301 /d/file.html http://www.domainname.com/r/file.html

5. Creating a Custom Error Page

Are you as tired as me of the default layout of 404 error pages? Well now you can easily create your own and refer to it like this:

1 ErrorDocument 401 /error/401.php
2 ErrorDocument 403 /error/403.php
3 ErrorDocument 404 /error/404.php
4 ErrorDocument 500 /error/500.php

6. Create an IP Banlist

Tired of getting the same bs comments specific user over and over again? Just ban the bastard like this by adding the following code to your .htaccess file:

1 allow from all
2 deny from 145.186.14.122
3 deny from 124.15

7. Set Default Email Address For Server Admin

Using the following code you can specify the default email address for the server’s admin.

1 ServerSignature EMail
2 SetEnv SERVER_ADMIN default@domain.com

8. Disable Display of Download Request

Usually when downloading something from a web site, you’ll be prompted if you wish to open the file or save it on your hard-disk. To prevent the server from prompting users wether they wish to open or save the file and to just save the file, use the following code:

1 AddType application/octet-stream .pdf
2 AddType application/octet-stream .zip
3 AddType application/octet-stream .mov

9. Protect a Specific File

The following code allows you to deny access to any file you wish by throwing an 403 error when it is trying to be accessed. In the following example I’ve chosen to protect the .htaccess file by adding an extra layer of security.

1 #Protect the .htaccess File
2 <files .htaccess="">
3 order allow,deny
4 deny from all
5 </files>

10. Compress Components With mod_deflate

As an alternative to compressing files with Gzip, you can use mod_deflate(which is supposively faster). Place the following code at the top of your .htaccess file(tip: you can also add .jpg|.gif|.png|.tiff|.ico mod_deflate those):

1 <ifmodule mod_deflate.c="">
2 <filesmatch .(js|css)$="">
3 SetOutputFilter DEFLATE
4 </filesmatch>
5 </ifmodule>

11. Add Expires Headers

The following code shows you how to add an expiration date on the headers.

1 <filesmatch .(ico|pdf|flv|jpg|jpeg|png|gif|swf)$="">
2 Header set Expires "Wed, 21 May 2010 20:00:00 GMT"
3 </filesmatch>

12. Setting the Default Page

You can set the default page of a directory to the page of your choice. For example in this code the default page is set as about.html instead of index.html

1 #Serve Alternate Default Index Page
2 DirectoryIndex about.html

13. Password Protect Your Directories and Files

You can enable password authentication for any directory or file on your server by using the following code:

01 #password-protect a file
02 <files secure.php="">
03 AuthType Basic
04 AuthName "Prompt"
05 AuthUserFile /home/path/.htpasswd
06 Require valid-user
07 </files>
08
09 # password-protect a directory
10 resides
11 AuthType basic
12 AuthName "This directory is protected"
13 AuthUserFile /home/path/.htpasswd
14 AuthGroupFile /dev/null
15 Require valid-user

14. Redirect an Old Domain to a New Domain

By using the .htaccess file you can redirect a old domain name to a new domain by adding the following code into the htaccess file. Basically what it does is it will remap the old domain to the new one.

1 #Redirect from an old domain to a new domain
2 RewriteEngine On
3 RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]

15. Force Caching

The following code will not directly increase the loading speed of your website. What it will do is, load the content of your site faster when the same user revisits your website by sending 304 status when requested components have not been modified. You can change the cache expiry by changing the number of seconds(it’s currently set at 1 day).

1 FileETag MTime Size
2 ExpiresActive on
3 ExpiresDefault "access plus 86400 seconds"

16. Compress Components By Enabling Gzip

By making use of Gzip you can compress files in order to make your website load faster.

1 AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
2 BrowserMatch ^Mozilla/4 gzip-only-text/html
3 BrowserMatch ^Mozilla/4.0[678] no-gzip
4
5 BrowserMatch bMSIE !no-gzip !gzip-only-text/html

17. Remove “category” from a URL

To transform this url: http://yourdomain.com/category/blue to -> http://yourdomain.com/blue, just add the following code at the bottom of your .htaccess file.

1 RewriteRule ^category/(.+)$ http://www.yourdomain.com/$1 [R=301,L]

18. Disable Directory Browsing

To prevent people from accessing any directories that might contain valueble information or reveal security weaknesses(e.g. plugin directories of wordpress), add the following code to your .htacess file:

1 Options All -Indexes

19. Redirect WordPress Feeds to FeedBurner

The following snippet redirects WordPress’ default RSS feed feedburner’s feed.

1 #Redirect wordpress content feeds to feedburner
2 <ifmodule mod_rewrite.c="">
3 RewriteEngine on
4 RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
5 RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
6 RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/yourfeed [R=302,NC,L]
7 </ifmodule>

20. Deny Comments from No Referrer Requests

The problem is that bots just post comments about how to increase your private parts all naturally to your blogs without coming from any other site. It’s like they fall from the sky. This neat hack prevents people from posting if they did not come from somewhere else(they can comment just fine if they came from e.g. google).

1 RewriteEngine On
2 RewriteCond %{REQUEST_METHOD} POST
3 RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
4 RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
5 RewriteCond %{HTTP_USER_AGENT} ^$
6 RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Source: How to: Deny comment posting to no referrer requests

21. Remove File Extension From URL

Thanks to Kartlos Tchavelachvili for this one. What the following code does is, it removes the .php extension(you can change it to whatever you like e.g. html) in a url. It makes the URL prettier & SEO friendlier.

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

22. Remove www from URL

Thanks to Mahalie for the following 2 .htaccess codes.
If you wish to take out the www from your website’s URL and transform it from http://www.example.com into http://example.com, add the following to your .htaccess.

1 #remove www from URI
2 RewriteEngine On
3 RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
4 RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

23. Add Trailing Slash to URL

Some search engines remove the trailing slash from urls that look like directories – e.g. Yahoo does it. But – it could result into duplicated content problems when the same page content is accessible under different urls. The following code makes sure there’s a slash at the end of your URL:

1 #trailing slash enforcement
2 RewriteBase /
3 RewriteCond %{REQUEST_FILENAME} !-f
4 RewriteCond %{REQUEST_URI} !#
5 RewriteCond %{REQUEST_URI} !(.*)/$
6 RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

24. Remove the www. from your website’s URL

Below I’ve provided a simple htaccess snippet to forcefully remove the “www” from your website’s URL.

1 # Redirect if www.yourdomain.com to yourdomain.com
2 RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
3 RewriteRule (.*) http://example.com/$1 [R=301,L]

Be aware that mod_rewrite (RewriteRule, RewriteBase, and RewriteCond) code is executed for each and every HTTP request that accesses a file in or below the directory where the code resides, so it’s always good to limit the code to certain circumstances if readily identifiable.

For example, to limit the next 5 RewriteRules to only be applied to .html and .php files, you can use the following code, which tests if the url does not end in .html or .php and if it doesn’t, it will skip the next 5 RewriteRules.


RewriteRule !\.(html|php)$ - [S=5]
RewriteRule ^.*-(vf12|vf13|vf5|vf35|vf1|vf10|vf33|vf8).+$ - [S=1]
Options +FollowSymLinks

RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule ^(.*)$ http://www.askapache.com/$1 [R=301,L]

Sometimes your rewrites cause infinite loops, stop it with one of these rewrite code snippets.

RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
RewriteRule .* - [L]

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

This is probably my favorite, and I use it on every site I work on. It allows me to update my javascript and css files in my visitors cache’s simply by naming them differently in the html, on the server they stay the same name. This rewrites all files for /zap/j/anything-anynumber.js to /zap/j/anything.js and /zap/c/anything-anynumber.css to /zap/c/anything.css

RewriteRule ^zap/(j|c)/([a-z]+)-([0-9]+)\.(js|css)$ /zap/$1/$2.$4 [L]

When you use flash on your site and you properly supply a link to download flash that shows up for non-flash aware browsers, it is nice to use a shortcut to keep your code clean and your external links to a minimum. This code allows me to link to site.com/getflash/ for non-flash aware browsers.

RewriteRule ^getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash [NC,L,R=307]

On many sites, the page will be displayed for both page.html and page.html?anything=anything, which hurts your SEO with duplicate content. An easy way to fix this issue is to redirect external requests containing a query string to the same uri without the query_string.

RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/
RewriteCond %{QUERY_STRING} !^$
RewriteRule .* http://www.askapache.com%{REQUEST_URI}? [R=301,L]

This .htaccess rewrite example invisibly rewrites requests for all Adobe pdf files to be handled by /cgi-bin/pdf-script.php

RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf-script.php?file=$1.pdf [L,NC,QSA]

For sites using multiviews or with multiple language capabilities, it is nice to be able to send the correct language automatically based on the clients preferred language.

RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
RewriteRule ^(.*)$ - [env=prefer-language:%1]

This allows access to all files by php fopen, but denies anyone else.

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.+$ [NC]
RewriteRule .* - [F,L]

If you are looking for ways to block or deny specific requests/visitors, then you should definately read Blacklist with mod_rewrite. I give it a 10/10

This can be very handy if you want to serve media files or special downloads but only through a php proxy script.

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.*\ HTTP [NC]
RewriteRule .* - [F,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^askapache\.com$ [NC]
RewriteRule ^(.*)$ http://askapache.com/$1 [R=301,L]

Uses a RewriteCond Directive to check QUERY_STRING for passkey, if it doesn’t find it it redirects all requests for anything in the /logged-in/ directory to the /login.php script.

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !passkey
RewriteRule ^/logged-in/(.*)$ /login.php [L]

If the QUERY_STRING has any value at all besides blank than the?at the end of /login.php? tells mod_rewrite to remove the QUERY_STRING from login.php and redirect.

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule ^login.php /login.php? [L]

An error message related to this isRequest exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.or you may seeRequest exceeded the limit,probable configuration error,Use 'LogLevel debug' to get a backtrace, orUse 'LimitInternalRecursion' to increase the limit if necessary

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^(.*)\.php$ /$1.html [R=301,L]

Redirects all files that end in .html to be served from filename.php so it looks like all your pages are .html but really they are .php

RewriteRule ^(.*)\.html$ $1.php [R=301,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# If the hour is 16 (4 PM) Then deny all access
RewriteCond %{TIME_HOUR} ^16$
RewriteRule ^.*$ - [F,L]

Converts all underscores “_” in urls to hyphens “-” for SEO benefits… See the full article for more info.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]

RewriteCond %{ENV:uscor} ^Yes$
RewriteRule (.*) http://d.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$     [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Full article:Redirecting Wordpress Feeds to Feedburner

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/feed\.gif$
RewriteRule .* - [L]

RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Article: Request Methods

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !^(GET|PUT)
RewriteRule .* - [F]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
RewriteEngine On
SetEnvIfNoCase X-Forwarded-For .+ proxy=yes
SetEnvIfNoCase X-moz prefetch no_access=yes

# block pre-fetch requests with X-moz headers
RewriteCond %{ENV:no_access} yes
RewriteRule .* - [F,L]

This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.

This module operates on the full URLs (including the path-info part) both in per-server context (httpd.conf) and per-directory context (.htaccess) and can generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput.

Add Second Administrator on Server 2003

April 13th, 2010

Method:

Click the Start button, then Run…

Then type “lusrmgr.msc” without the quotes

In the window that opens, right click in the right panel and click “New User”

In the New User dialog, type in your preferences for a new user name and password (this will be our secondary Administrator account).  Uncheck User must change password, and check Password never expires

Now, right click the new user and click Properties in the pop up menu

Go to the “Member of” tab and press the Add button

Type “Administrators” without the quotes, then press the Check Names button (to complete the name, it will add the name of your computer) and press OK when it is done, then press OK on the Local Users and Groups dialog

How to backup and restore PostgreSQL

April 2nd, 2010

:: Windows::

I was fairly impressed with pgAdmin III when I first used it. It seems to be simple to use for anyone who can’t write their own SQL statements. I wasn’t too good and it and each time I execute a change in the database I have a feeling the world’s going to end. But one thing the pgAdmin III doesn’t do well is backup and restore.

Using pgAdmin III for PostgreSQL

(Using pgAdmin III for PostgreSQL. A screenshot.)

0. Objective

In the end it’s best to use the command prompt (or terminal) and in this really beginner tutorial, we’ll do a backup and restore using the command line.

1. Set PATH for PostgreSQL in Windows Vista

This guide assumes you install in ‘C:\Program Files\PostgreSQL\8.3\’, the default installation directory.

If you are using Microsoft Windows XP or Vista, you may need to add in the PATH of PostgreSQL’s bin to your environment variables. We can do so by going to your Control Panel and type ‘environ…’ at the search area. We’ll get the following:

Editing system environment variables in Windows Vista.

Click on ‘Edit the system environment variables’, a dialog box will pop up. Click on ‘Environment Variables…’, you should be greeted with the following dialog box:

Editing the path for environment variables

My path looks like this before I add anything:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

Append these two directories at the back of what is already there:

;C:\Program Files\PostgreSQL\8.3\bin

The folder ‘bin’ contains all the programs that of PostgreSQL like pg_dump and psql. It allows you to run psql in the command prompt without having to be in the “C:\Program Files\PostgreSQL\8.3\bin” directory.

2. Backing up in the command prompt

To backup in PostgreSQL, you can run the following command:

pg_dump -U myusername mydb > mydb.sql

As you can probably guess “myusername” is the username I am using and the database I would like to backup is named “mydb”. You will be prompted by the password.

Running pg_dump in the command prompt in Windows Vista

(Running pg_dump in the command prompt in Windows Vista.)

The above command would create “mydb.sql” in the current folder that your command prompt is in. As you can see my current folder is “C:\Users\KahWee”. You can check your folder after running that command.

3. Restoring in the command prompt

Restoring is pretty similar to backing up. To restore in PostgreSQL, you can make use of psql:

psql -U myusername mydb < mydb.sql

This runs every single command in the file “mydb.sql”. That’s all, hope it helps.

Oh, and by the way, to run SQL statements in the command prompt:

psql -U myusername mydb

Then just type your SQL statements followed by the semicolon and press enter. The SQL command only executes after your semicolon.

::Linux::

PostgreSQL is a one of the robust, open source database server. Like MySQL database server, it provides utilities for creating a backup.

Step # 1: Login as a pgsql user

Type the following command:
$ su - pgsql
Get list of database(s) to backup:
$ psql -l

Step # 2: Make a backup using pg_dump

Backup database using pg_dump command. pg_dump is a utility for backing up a PostgreSQL database. It dumps only one database at a time. General syntax:
pg_dump databasename > outputfile

Task: dump a payroll database

Type the following command
$ pg_dump payroll > payroll.dump.outTo restore a payroll database:
$ psql -d payroll -f payroll.dump.outOR$ createdb payroll
$ psql payroll
However, in real life you need to compress database:$ pg_dump payroll | gzip -c > payroll.dump.out.gzTo restore database use the following command:$ gunzip payroll.dump.out.gz
$ psql -d payroll -f payroll.dump.out
Here is a shell script for same task:

#!/bin/bash
DIR=/backup/psql
[ ! $DIR ] && mkdir -p $DIR || :
LIST=$(psql -l | awk '{ print $1}' | grep -vE '^-|^List|^Name|template[0|1]')
for d in $LIST
do
  pg_dump $d | gzip -c >  $DIR/$d.out.gz
done

Another option is use to pg_dumpall command. As a name suggest it dumps (backs up) each database, and preserves cluster-wide data such as users and groups. You can use it as follows:$ pg_dumpall > all.dbs.outOR$ pg_dumpall | gzip -c > all.dbs.out.gzTo restore backup use the following command:
$ psql -f all.dbs.out postgres

How To Install Dreamweaver CS4 In Ubuntu

April 2nd, 2010

It would be great if there is a Linux build of the popular Dreamweaver CS3, or that it could be easily installed via WINE. The truth is, none of the above work. There is no Linux version, nor will it work via WINE direct installation. The only way to get it to work is to port it over from a Windows installation. If you are new to Dreamweaver CS3, it is one of the best, if not, the best web editor software in the market. While there are many open source and free web editors out there, none of them come close to it in term of quality and capability. Although it comes with a hefty price tag of $399, it is well worth the money if you are into serious web developing. As such, if you wish to follow this guide and install Dreamweaver CS3 in your Ubuntu machine, please make sure you have the licensed copy, or proceed to Adobe to make your purchase. Do not attempt to use illegal software. Initial Installation – WINE We will need WINE to create a Windows environment for Dreamweaver. If you have already installed WINE, you can skip to the next section. sudo apt-get install wine winecfg The WINE configuration window will pop up. Click OK to close the window. You can now find a .wine folder in your Home directory (if you can’t see it, go to View and check “Show Hidden Files“). Porting Dreamweaver CS 3 From Windows Install your Dreamweaver CS 3 in Windows. (For this step, I would advise you to install it on a Windows virtual machine so that you can transfer files between the two OS easily later on.) Now there are 5 main folders that you need to copy to your Ubuntu machine. 1) Open up File Manager and navigate to C:\Program Files. Copy the whole ‘Adobe‘ folder to Ubuntu /home/username/.wine/drive_c/Program Files folder. 2) Still in the Windows File manager, navigate to C:\Documents and Settings\your-windows-user-name\Application Data (if you can’t find the Application Data folder, go to Tools->Folder Option->View and select ‘show hidden files and folders‘) and copy the whole ‘Adobe‘ folder to Ubuntu /home/username/.wine/drive_c/windows/profiles/All Users/Application Data/ 3) In the Windows File manager, go to C:\Program Files\Common Files and copy the whole ‘Adobe‘ folder to Ubuntu /home/username/.wine/drive_c/Program Files/Common Files 4) In the Windows file manager, go to C:\WINDOWS\system32 and copy the whole ‘marcomed‘ folder to Ubuntu /home/username/.wine/drive_c/windows/system32 5) In the Windows file manager, go to C:\WINDOWS and copy the whole ‘WinSxS‘ folder to Ubuntu /home/username/.wine/drive_c/windows Next, we need to import the Dreamweaver registry to WINE. In your Windows, go to Start->Run. Type in ‘regedit‘ and press Enter. In the window that pop up, on the left pane, navigate to HKEY_LOCAL_MACHINE-> SOFTWARE->Adobe->Dreamweaver. Right click on the ‘Dreamweaver‘ folder and select ‘Export’. Save the file as dreamweaver.reg Copy this dreamweaver.reg to your Ubuntu home folder. Now you need to convert the registry file to ASCII format. sudo apt-get install recode recode ucs-2..ascii dreamweaver.reg wine regedit dreamweaver.reg At this time, you have successfully ported all the necessary files from Windows to Ubuntu. To test your installation: cd .wine/drive_c/Program\ Files/Adobe/Adobe\ Dreamweaver\ CS3/ wine Dreamweaver.exe Dreamweaver CS3 should now launch. Creating entry in Applications menu To create an entry in your Applications menu, right click on the Applications menu and select ‘Edit Menus’. Scroll down to the Wine->Programs entry and select New Item. Enter the following Type: Application Name: Dreamweaver CS3 Command: wine /home/username/.wine/drive_c/Program\ Files/Adobe/Adobe\ Dreamweaver\ CS3/Dreamweaver.exe Click Close. You should now see an entry in your Application menu. You can drag the entry to your desktop or to the panel to create a shortcut.

source: http://maketecheasier.com/how-to-install-dreamweaver-cs3-in-ubuntu-hardy/2008/06/20