Apr 13 2009

Ubuntu 9.04 boots in 17.5 seconds!

So how fast did Ubuntu 9.04 boot with a solid-state drive? Really freaking fast. Like, “I can’t believe it’s already done” fast. Well, here, watch for yourself:

Share

Apr 12 2009

INCREASE SEO with this mod_rewrite tutorial. Only the useful.

Since I didn’t really delve into how to actually use mod_rewrite to do something useful in my last post I will now.
The main reason I got mod_rewrite going is to improve my search ranking for a few sites so I’ll show how to do this with a dynamic php site.
What I primarily aimed at was to get $_GET variables to look like directories.

The .htaccess file from the previous post was


1. RewriteEngine on
2. RewriteRule ^/?test\.html$ test.php [L]

First line obviously turns on the .htaccess Rewrite Engine. .htaccess files can be used for other stuff. Check here for an example of a different use of a .htaccess file.

The second line is rewriting test.html to test.php. The text before the space represents the string to search and replace using regular expressions. The text after the space specifies what to replace the aforementioned string with.

This rule is really simple. The special characters that denote the regular expression are:

‘^’ This symbol, the caret, signifies the start of the URL.
This is under the current directory. Think of it like the ‘~’ character on the command line.
If your site is http://www.quick-content.com then
the ‘^’ in these regular expressions are the equivalent of the that URL
(as long as the htaccess file is in the root directory for that site).

‘$’ This symbol, the dollar sign, signifies the end of the URL.

“\.’ This is just a period. There is nothing special about this because it is ‘escaped’ by the slash.
For the search this will look just tell apache to treat it like a normal period.
This is necessary because the period has a special meaning and in this case we just
want to look for a period and not any character (which is the ‘.’s normal meaning).

It’s great and all to redirect from one file to another using mod_rewrite and apache but it’s not that helpful for SEO.
Here is another search and replace rewrite rule:


RewriteRule ^posts/([^/\.]+)\.html$ single_post.php?post_name=$1 [L]

This rule isn’t that simple.
First we want to match all urls that start with ‘posts/’.
Then we want to capture the characters that come after ‘post/’ but before ‘.html’ and use them as the get variable for the single_post php script.

This will rewrite pages like :
http://www.quick-content.com/posts/techstuff.html
to
http://www.quick-content.com/single_post?post_name=techstuff

The ‘()’ brackets tell apache to take whatever is inside of them and put it in a temporary location that can be acessed by the replacement string.
In this case the string ‘somepost’ is stored as $1. If you had multiple parenthesis then the $2,$3,.. would be used also.

The square brackets signify an expression of a sort. [0-9] will match any digit between 0 and 9. [^0-9] will match any character that is not between 0 and 9.
So [^/\.]+ matches one or more characters that are not a slash or a dot.

After that the ‘\.html$’ searches for the .html file extension so that url will look like a basic old html file.

A general overview of the structure of a mod_rewrite RewriteRule:


RewriteRule Pattern Substitution [OptionalFlags]

Fairly simple right? RewriteRules are dissected as follows:

RewriteRule
This is just the name of the command for apache.

Pattern
This is a regular expression which will be applied to the current URL.

Substitution
Substitution occurs in the same way as it does in Perl or PHP.

You can include backreferences and server variable names in the substitution. Backreferences to this RewriteRule should be written as $N, whereas backreferences to the previous RewriteCond should be written as %N.

A special substitution is -. This substitution tells Apache to not perform any substitution.

OptionalFlags

Any flags should be surrounded in square brackets and comma separated. The most useful are:

F – Forbidden. The user will receive a 403 error.
L – Last Rule. No more rules will be proccessed if this one was successful.
R[=code] – Redirect. The user’s web browser will be visibly redirected to the substituted URL.
If you use this flag, you must prefix the substitution with http://www.site.com/

There are more flags but I haven’t had a use for them yet.

I did up a few other more complex rewrites for one of my dynamic sites.


RewriteRule ^([0-9]+)/([0-9]+)/?$ /index.php?num_posts=$1&start=$2  [L]

This one is pretty straight-forward if you understood the previous example.
It is looking for two numerical strings separated by slashes. It then takes those two values and places them as the
$_GET[‘num_posts’] and $_GET[‘start’] variables. The ‘/?’ at the end allows for a possible slash.
[0-9]+ means: match one or more characters that are between 0 and 9.

The main problem that I ran into was that after a rewrite all of the images and includes would not work because I’m lazy and use relative paths.
So when I type a url like www.quick-content.com/10/11023/ I don’t get any images or style sheets because the browser is trying to find images
at www.quick-content.com/10/images/. I had to write two rules to make this work properly:


RewriteRule ^.*/?.+/images/(.+)$ /images/$1 [L]
RewriteRule ^.*/?.+/includes/(.+)$ /includes/$1 [L]

These rules check for one or more directories before the image or includes directory and if they exist then it rewrites the url to either /images or /includes.
The ‘.*/?’ means 0 or more characters before an optional slash (the ‘?’ following the slash means that it is optional).
‘.+/images/’ and ‘.+/includes/ tries to match one or more characters before the image or includes directory.
The ‘.’ means any character. So ‘.*’ means 0 or more any characters which is essentially any string.

Hopefully that wasn’t too confusing. There are a lot of great resources out there for learning regular expressions if you still don’t get it.
-Cody Taylor

Share

Apr 12 2009

Use apt-p2p To Improve Ubuntu 9.04 Upgrade

An anonymous reader writes “With Jaunty Jackalope scheduled for release in 12 days on April 23, this blog posting describes how to switch to apt-p2p in preparation for the upgrade. This should help significantly to reduce the load on the mirrors, smooth out the upgrade experience for all involved, and bypass the numerous problems that have occurred in the past on Ubuntu release day. Remember to disable all third-party repositories beforehand.”

Read more of this story at Slashdot.

Share

Apr 12 2009

Setting up mod_rewrite on ubuntu example. Only the useful.

mod_rewrite is a way to change one url to another. It is very useful for making dynamic php sites better for search engine optimization (SEO).

Obviously you’re going to need apache installed. I’m using Apache 2.0 with php5. This is how I did it.

I had hoped that it was already installed and I could just start writing regular expressions in an htaccess file and have everything work. So I went to check if it was installed by calling the phpinfo function. I created a file called asdf.php which contained:

I then did a search for rewrite in my browser. No go. So it’s either not installed or not enabled.
I checked the /etc/apache2 directory for any files that look like mod_rewrite.
I found rewrite.load in the mods-available directory. There is also a mods-enabled directory so I copied rewrite.load to mods-enabled with this command.


cody@taylor:/etc/apache2$: sudo cp rewrite.load ../mods-enabled/rewrite.load

I thought this may do it so I restarted apache2 with this command:


cody@taylor:/etc/apache2$: /etc/init.d/apache2 restart

I created two text files to test whether it was working:


filename: test.html
This is a HTML File

filename: test.php
This is a PHP File

I then created a .htaccess file in my web root directory which contained this text:


RewriteEngine on
RewriteRule ^/?test\.html$ test.php

I went to http://localhost/test.html hoping to see that it’s a php file. Didn’t work obviously.
I checked the sites-enabled directory and opened 000-default in vim.

It contained :

ServerAdmin webmaster@localhost
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ “/usr/share/doc/”
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128

AllowOverride is what I was looking for so I change AllowOverride to all and restart apache again.
This time when i check http://localhost/test.html I get that it is a php file which is good.

I noticed I was getting this error when I restarted apache:


cody@taylor:/etc/apache2$: sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

I fixed this by adding this line to the apache2.conf file:


ServerName "codytaylor.org"

A restart fixed it all up.

-Cody Taylor

Share

Apr 9 2009

Decent DVD-Ripping Solution For Linux?

supersloshy writes “I’m a user of Ubuntu Linux and I have been for a little while now. Recently I’ve been trying to copy DVDs onto a portable media player, but everything I’ve tried isn’t working right. dvd::rip always gets the language mixed up (for example, when ripping ‘Howl’s Moving Castle,’ one of the files it ripped to was in Japanese instead of English), Acidrip just plain isn’t working for me (not recognizing a disc with spaces in its name, refusing to encode, etc.), Thoggen is having trouble with chapters (chapter 1 repeated twice for me once), and OGMRip has the audio out of sync. What I’m looking for is a reliable program to copy the movie into a single file with none of the audio or video glitches as mentioned above. Is there even such thing on Linux? If you can’t think of a decent Linux-based solution, then a Windows one is fine as long as it works.”

Read more of this story at Slashdot.

Share

Apr 9 2009

Linux Mint 6 “Felicia” KDE released!

“This edition is based on Kubuntu 8.10 Intrepid Ibex, Linux 2.6.27, Xorg 7.4 and it comes with KDE 4.2 and Amarok 2.0”

Share

Apr 8 2009

Ubuntu accuses Microsoft of Linux netbook FUD

If you think that Windows now completely rules the netbook world, you’ve been drinking way too much Microsoft kool-aid according to Canonical, the company behind Ubuntu.

Share

Apr 4 2009

Portable Ubuntu Runs Ubuntu Inside Windows

Free application Portable Ubuntu for Windows runs an entire Linux operating system as a Windows application. As if that weren’t cool enough, it’s portable, so you can carry it on your thumb drive

Share

Apr 1 2009

How-To: Install Ubuntu and Linux Apps on Your PlayStation 3

If you’re only using your 0 PlayStation 3 for console gaming, you’re missing out on half of its hidden versatility: the ability to upgrade into a fully functional PC!

Share

Mar 31 2009

8 Rocking Linux Distros

Defining the best Linux distros is like defining the best car–one does not exist; instead, the best cars are the ones that meet your needs, and your needs may vary wildly from the needs of another person. Just as an F150 might be the best vehicle for you and a Civic for me, Ubuntu might be what you need from Linux while I’ll be fine with DSL.

Share