Apache - Selectively Disabling mod_rewrite

Say you have redirect a domain from .net to .com and have a rule such as:

# Rewrite to the new domain and add "www"
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]

These are catch all rules, which check if the host is domain.net, if not it just redirects it to it. (See the motives why you should use "www" or base domains and never both on this page)

In this scenario, if you want to disable rewriting for a certain folder for the .net domain, you can add the following rule at the top of the code:

RewriteRule ^/oldfolder(.*)? - [L]
# Rewrite to the new domain and add "www"
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]

Here we will match the folder and stop there, thereby serving the page from the alternative domain name (a .net domain) for the specified folder.

http://www.domain.net/oldfolder/somethingelse

If you need more information on www or non-www URL rewriting, please see the www-redirection tutorial page.

Apache - URL Rewriting To WWW or non-WWW Domains Names

A small error with web server configurations continues to be a source of headaches on the web: the lack of redirection to the WWW sub-domain.

To do the rewriting I'll be focusing on Apache's mod_rewrite, which is one of the more widely available solutions to the problem.

This code is what you need if you use a .htaccess file on your server:

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

There's another option when you want to keep it stored in a safer location, which is including it in Apache's httpd.conf file:

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

These two blocks of code have slight differences. Notice RewriteRule here has a forward slash, replacing the RewriteBase / directive on the previous example. While they do the same thing, they are not interchangeable depending on which configuration file you use.

Don't forget the escape character for the dot on RewriteCond rules - even though it is unlikely you'll match something.

If after you've done this, you need to exclude some folders/paths from the URL redirection you've just inserted, see the instructions on the Selectively Disabling mod_rewrite post.

Bash - Sending E-Mail From The Command Line

This guide outlines the requirements to send e-mail from the bash command line on Gentoo Linux but the instructions are mostly the same for Red Hat Enterprise Linux, OpenSUSE, Debian, Ubuntu or Slackware. Just replace emerge by your distro's package manager of choice, like yum, zypper or apt-get commands.

First, install the "mail-client/mailx" package by using emerge, as root:

emerge mail-client/mailx

echo "Hello World!" | mail -s Subject destination@mailserver.com

This assumes you already have "postfix" installed and configured, which you can check how to do here:

emerge postfix
/etc/init.d/postfix start

The test e-mail should arrive to your destination e-mail box of choice. Script away using the command to send e-mails in batch or to warn the sysadmin of problems in the box.

Cluster - TORQUE Resource Manager Tutorial

The TORQUE resource manager is a complex piece of software, which deserves some quick tips on how to use the system without having downtime or lost jobs for your users. This page gathers some of the most important information you can know about using Torque and will be further expanded to accommodate all the important topics regarding this management component of computer clusters.

TORQUE is built on the principles of the Portable Batch System, also known as PBS, from which there are two versions OpenPBS(opensource but no longer maintained) and PBS Pro, a paid for PBS software. TORQUE is also open source and derives from OpenPBS, with currently many years of development separating TORQUE from OpenPBS. TORQUE is currently one of the better ways to manager cluster job queues, especially given that Sun Grid Engine is no longer free.

TORQUE PBS Server

The pbs_server process is what controls what nodes are assigned idle jobs from the queue on a machine(node) finishes a calculation and becomes empty. Sometimes it can have some problems, so it is useful to restart the pbs_server process, which usually is installed in /etc/init.d/pbs_server.

Restart PBS Server by issuing, as root(or with sudo):

/etc/init.d/pbs_server restart

The process can be restarted mostly without issue and there are two options for restarting the process, defined in TORQUE's config file:
  • delay
  • quick
If PBS_SERVER_STOP is set to "quick". In this situation, the running jobs will be let run without interaction until the server is back up. Setting it to "delay", the jobs will be checkpointed, rerun, or pbs_server will wait for the jobs to finish before restarting the service.
If you're trying to sort out blocked resources, it is recommended to use "quick".