SEO Your Application With mod_rewrite

Generally speaking, many search engines like Google, MSN, and Yahoo like to see your URLs be as pretty as possible. Using applications like PHP will often produce URLs that look like this: http://somesite.com/index.php?section=section1&data=test. These URLs are typically frowned upon by the search engines and can produce mixed results when attempting to achieve the  highest search engine ranking.

There are two methods we can use to make our URL’s a bit more friendly. Many applications today already provide pre-packaged .htaccess files. It’s important for me to explain that there are two methods for setting up mod_rewrite rules. The first (and most common) method is to use a file called “.htaccess” placed in the root directory of your web site. This file is read in to the Apache configuration in real time (The AllowOverride option in your Apache configuration controls this). We’ll cover the .htaccess method here.

The .htaccess Method

This is the most common way to implement mod_rewrite rules. First, open a text file with your favorite editor (if you do not have shell access simply use notepad or vi on your local machine). Remember that a dot (.) before the file name designates this file as hidden in Linux.

For our example we’re going to redirect http://somesite.com/index.php?section=section1&data=test to look like this: http://somesite.com/section1/test.

  1. Edit the .htaccess file you wish to
    # vi /var/www/html/.htaccess
  2. Place the following in the new .htaccess file:
    RewriteEngine On
    RewriteRule ([^/]+)/([^/]+)?$ index\.php?section=$1&data=$2 [L]
  3. Save the file and exit your editor.
    (* Note: If you upload this file with an FTP/SCP program your file will not appear as it is hidden, if you need to delete the file due to a misconfiguration, issue “DELE .htaccess” in the directory you uploaded the file.)

The [L] directive tells mod_rewrite to redirect the request with a 301 redirect.

Troubleshooting

  1. I receive a 500 server error after uploading.
    Check to make sure no typo’s were made. Check the apache error_log for any clues.
  2. The redirect does not take place but the site still shows.
    This is usually because your host does not support mod_rewrite or is not allowing .htaccess files. To check if .htaccess is being parsed open a new .htaccess and put the following inside:
    Redirect /test “http://www.google.com”
    If this works you can safely assume that .htaccess files are being parsed.

Top 10 Linux Commands Anyone Can Use

As we continue to find Linux loaded on more and more consumer-based PC’s the reality of Linux everywhere has come to fruition. I’m relatively excited that Ubuntu is being endorsed by companies like Dell. As more and more PC’s ship image with Linux pre-loaded it’s almost necessary to become acquainted with the Linux shell. For those of you from the Microsoft days I would almost consider the Linux shell to be the DOS of Windows 3.1/95/98 (WinXP just emulated the shell). In the blurb below I try to make correlations to Windows commands to help you grasp what each command does.

Anyway, here ten of the commands I think you should know when using Linux as a first-time user. Note that when typing these commands the # sign symbolizes the shell prompt and you shouldn’t type it 🙂

Commands

  1. man
    I think the first command anyone should know is man. Man is short for "manual". This command provides you with details about any command (You can even "man man" from the command). Think of this as the F1 key in your standard Windows installation.

    # man <command>

    Example:
    # man ls

    image

    Type "q" on the keyboard to exit.

  2. ls
    Now that we know how to see what commands do, we need to know how to see files on the file system. The ls command shows you a listing of all files in a given directory. If no directory is specified, the command returns a listing of files and directories in the current working directory (CWD). Specify a directory after ls and receive a listing of that directory.

    # ls <directory,optional>

    Example:
    # ls /etc

    image

  3. vi
    If you want to hang with the pros you should probably take a short amount of time and pick up vi. VI is the Linux text editor of choice for the command line. Think of VI as your quick notepad in Windows. Specify a file after the vi command to open the file. Use the arrow keys to navigate the text file.

    Use the following basic commands to navigate vi:

    a.) /<search string> (searches for a string)
    b.) :w (writes the open file)
    c.) :q! (quit without saving changes)
    d.) :wq (write changes and quit)
    e.) :q (quit vi)

    Type "i" to enter editing mode. Hit escape after making your changes to enter the commands above.

    # vi <file to edit>

    Example:
    # vi /etc/fstab

  4. find
    Have you ever lost it? What if you never had it? Enter find. Find’s only similarity, to that annoying puppy in Windows XP, is that it will find your files. Other than that, this utility does its job effortlessly.

    # find <path> -name <name of file>

    Example:
    # find / -name foo.txt
    (This command finds "foo.txt" anywhere starting with the root "/" of the file system)

    image

  5. cat
    This utility shows the contents of a given file. Think of this command as the Windows equivalent "type". Specify the name of the file you wish to display after the command and … presto!

    # cat <file to output>

    Example:
    # cat /etc/fstab

    image

  6. less
    This command receives input from STDIN (Standard Input) and allows you to page through the output. This is useful with the command mentioned above. What if you have too much data for your shell’s output buffer? You can’t scroll up. Enter less. Simply pipe the output of your program to less and it’ll show you a scrollable, searchable result. Use the space part to page down. Use the arrow keys to navigate up and down and type "/<search string>" to search.

    # <command> | less

    Example:
    # cat /etc/exim.conf | less

    image

  7. grep
    Grep allows you to search a file for a string. It’s very simple to use. After executing your grep, each line is printed which matches your string.

    # grep "string" <file>

    Example:
    # grep "sda" /etc/fstab

    image

  8. rm, cp and mv
    Here are a few commands you can’t live without: rm, cp, and mv.

    Windows Command Linux Equivalent
    del rm
    copy cp
    rename/move mv

    To remove a file use this syntax:
    # rm <file>

    To remove a directory and its files contained:
    # rm -rf <path to directory>

    To copy a file simply use the following syntax:
    # cp <source> <destination>

    To rename or move a file use the following syntax:
    # mv <source> <destination>

  9. ps
    PS or "process list" shows you a list of all running processes. The commonly used (at least for me) command with flags is:

    # ps aux

    This command shows you a list of all processes, which user they are running as and the command (truncated).

  10. chmod/chown
    Linux is a very secure Operating System. Its roots of security lay in its strict ACL (Access Control List) settings. Linux uses chmod (change file access permissions) and chown (change file owner and group) to modify user settings and ownerships.

    There are many ways to use chmod but we’ll explain the simplest.

    # chmod <modes> <file/directory>

    If we were to create a shell script and we wanted to set it executable we would perform the following chmod:

    # chmod +x script.sh

    If we wanted to set the file read/write/execute we could use this command:

    # chmod +rwx script.sh

    Chown simply changes the owner and/or group of the file. The old way of changing the ownerships was like this:

    # chown user.group <file/directory>

    To the best of my knowledge this command works but it is a bit outdated. Now simply replace the "." with ":" so the command looks like this:

    # chown user:group <file/directory>

    I want to change /etc/fstab to be owned by user award and group foogroup. (Don’t do this really hehe!) I would use this command:

    # chown award:foogroup /etc/fstab

Conclusion

There are quite a few commands available in the Linux world. It’s always a good idea to be comfortable with the command line. The command line becomes easier as you use it (I’ve been living in it for almost 10 years now). The power and flexibility the command line offers is unmatched by any GUI. As with everything I recommend that you learn something from the inside out. That being said, start out with the command prompt and play around. Load up a VM (Virtual Machine) with Ubuntu or CentOS and play around. Check out this article to see how to load VMware Server Beta and get started today.

Linux Security: List Listening Ports

There are a few ways to list all ports open and to show which daemons are listening. Simply run one of the two commands:

# lsof -i | grep "(LISTEN)"

Example output

image

-or-

# netstat -tupan | grep "LISTEN"

I believe this to be a cleaner output
image

DIY: Tornado Cruiser

Everyone knows there are tons of people out there chasing storms. This fellow happened to build his own tornado cruiser to keep up with them. This sounds like a DIY project waiting to be written up 😛

image imageimage imageimage image

RSYNC vs. Image-Level Backups

Backups are most important when you really need them. Most hosting companies, business and personal users implement their backups with traditional RSYNC. Since RSYNC can be piped over SSH it serves as a very secure way to perform backups of critical files. Using Rsnapshot can provide even more flexibility with snapshot capabilities.

imageWhat if you have thousands of files? What about millions of files? RSYNC  becomes very cumbersome as it has to walk every directory and every file to compare checksums, modified times and contents. RSYNC literally grinds to a halt as it attempts to tally file counts greater than 500,000 (at least on our system systems).

So what’s the solution? For many years we have been performing backups at the file level. imagePerforming backups at the file level adds latency and can be very time consuming. The new technology is CDP (Continuous Data Protection). This technology, in fact, is not very new at all. Faster Internet connections enable us to perform backups at the sector-level over the wire. Sector-level backups are so much faster because only the changed sectors are transmitted.

R1Soft has pioneered this technology in the Linux market. Their kernel device driver (the heart of their backup agent) actually tracks block-level changes in real time. The next time the backup kicks off the agent knows exactly what blocks have changed. You might be thinking to yourself "That has to add overhead!" but, in reality, it uses no more than 10MB of physical RAM per 100GB the device driver monitors.

image

Image level backups are so fast we can back up our web servers in less than 5 minutes every 2 hours. These backups are less CPU and disk intensive than any file-level backup can offer.

To test drive image-level backups with R1Soft technology, visit WebHostBackups.com for more information.

Your Datacenter: Greener

As prices and energy usage goes up top server manufacturers are finding ways to make the datacenter use less energy. This is a great idea because most servers are not utilized even 50% of their total capacity. Virtualization technologies like VMware can allow for more virtual servers to run on less hardware – I consider this to be a "green" technology. What are server manufacturers like Dell, IBM and Sun doing to help the green effort? They’re coming out with a line of servers focuses specifically on saving energy.

The problem gets worse because the industry has focused around developing the fastest dual and quad-core processors consuming more and more energy. Server racks are now using five to ten times the power as racks four years ago. The sad part is a large amount of the energy goes to waste. I believe that if projects from corporations were planned better they would consume less energy and money.

Using SED to replace newlines with commas

In the Linux world it is often necessary to manipulate data from commands in text form. Here’s a quick and easy way, using sed, to search for newlines in your output and insert commas where needed. This can be particularly useful if you intend on piping your output to an array for a script.

 

 

 

# sed -n ‘1h;2,$H;${g;s/\n/,/g;p}’ file.txt

Pretty ugly huh? That will get the job done with little effort. If you wish to replace the newlines in the file just use the -i flag with sed and your file will automagically be updated.

Review: Saitek Eclipse Keyboard

I finally broke down and purchased a new keyboard. I’m personally not into all the LED lights and special buttons on keyboards. I really like a responsive key and a fully-functional board. My old keyboard, a Microsoft media keyboard, just wasn’t cutting it anymore at my home office. The keys seemed to have long travel which exhausted my hands after long periods of typing. The whole think creeked when typing and it was completely white which doesn’t fit well into the look of my office.

After reading reviewed at NewEgg I decided to go with the Saitek Eclipse. This keyboard was purchased for $34.99 (plus shipping of course). I really needed the wrist-rest because of the desk I use in my office.

The keyboard arrived packed very well (as always from NewEgg) and, once theimage keyboard was removed from the packaging, seemed very stable and durable.  Many people say that the backlighting on the keys fades toward the top around the F keys but I don’t see such an effect. The keys do, however, seem to be dimmer if viewing the keyboard from an angle. Three modes are available for the backlit keys: on, dim, off. I personally keep the keyboard backlighting off in normal use as I purchased the board for the keying action.

The keyboard makes for an effortless typing experience. When I first started using the keyboard I wanted to type forever. I visited multiple forums and replied to many posts just because it felt good. This keyboard is really the best bang for your buck. I chose wired because I don’t really care to replace batteries and I want to make sure that I have the best connection possible.

I would highly recommend this keyboard to anyone. This keyboard is great for serious gamers and business users alike. They keyboard definitely has a unique look but seems to be sturdy and made with quality in mind.