Category Archives: Debian

Apache RewriteMap example

Today I needed to rewrite a list of about 1000 URL’s to a new location. Our product database was cleaned and new URL’s were created… Using RewriteMap from Apache’s Mod_rewrite comes in handy here.

In my case I needed to rewrite URL’s like this:

www.exampledomain.com/en/product1234/product_detail.php

to

www.exampledomain.com/en/travelbox_12/product_detail.php

Where in my URL’s I had a 1000 different ‘poducts1234’ to rewrite to a new URL.

 

Here’s the HOWTO:

Create a textfile on your server with 2 columns. Something that would look like this:

And save it to a folder you wish, eg

from this file,  create a rewrite database,  more info: httxt2dbm

Once done,  open your vhosts config and add the following configuration:

A bit of clarification:

The line with content:

creates a condition that if the rewritemap contains the URI and the value is not “” (so an empty string) then it should perform the RewriteRule.

The rewrite rule itself is pretty obvious. It’ll rewrite the URL’s for which the rewritemap is found to the new product URL, and also keep the trailing parameters.

Restore a single MySQL Table

If you ever had a problem with a MySQL Table being foobar because of a human error (or other bug), you might need to be able to restore only 1 single MySQL table.
Restoring an entire Database may cause other data loss, and this is of course something we don’t want.

So, if you have a mysql dump available, you can ‘filter’ our that specific table by using the sed command.

Let say the name of your table is tableToRestore and the file dbdump.sql is the file containing your database backup:

This will copy in the file dbdump.sql what is located between CREATE TABLE tableToRestore and the next CREATE TABLE corresponding to the next table.

You can then adjust the file dbdump_tableToRestore.sql which contains the structure of the table tableToRestore, and the data (a list of INSERT commands).

Configure NewRelic on Plesk

Installing NewRelic on a Plesk server is as straight forward as any other NewRelic installation. However… it’s not that easy to split up your PHP Applications on a per vhost configuration in Plesk.

I found this to be very usefull: pixlsHQ NewRelic Customer Template for Plesk

It adds the NewRelic Application names inside the by Plesk generated vhost configurations.

It’s very easy to implement, so I won’t explain here how to do it 🙂

Update November 12 – 2015:
The github link does no longer work on Plesk v12. However, the following easy work around is sufficient for my needs.
Just add

newrelic.appname = “{DOCROOT}”

to you Service Plans => PHP Settings => Additional configuration directives.

That way, you’ll get every subscriptions reported as a different Application with a name of: /var/www/vhosts/subscriptionname/httpdocs