Recent Entries

While developing the new DigitalOctane, we’ve had the opportunity try and make our site no only more search friendly, but also just easier on our visitors. In doing so we created some very simple changes to our .htaccess file in order to direct our users appropriately.

With out getting too deep into the inner workings of all the awesome things you can do within the .htaccess file.

I am making the assumption that you know what a .htaccess file is, and where it goes.

Let’s jump into the very most basic aspects of what we have going on.

Options +FollowSymlinks
RewriteEngine On

# Remove www from www.digitaloctane.com
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

RewriteRule ^company/(\w*+)$  /company/$1/ [R]
RewriteRule ^company/(\w*+)/$ /index.php?page=$1

RewriteCond %{HTTP_HOST} m.digitaloctane.com
RewriteCond %{REQUEST_URI} !^/mobile
RewriteRule ^(/)?$ /mobile.php?page=$1 [L]

Now lets breakdown each snippet from the example above.

Options +FollowSymlinks
RewriteEngine On

First off we are setting an option to tell Apache we are going to be creating “symlinks” (Symbolic Link). Basically this means that we are going typing in one URL and directing our users to another spot on our servers WITH OUT redirecting. This will make more sense momentarily.

Secondly “RewriteEngine On” is stating that we are going to be doing some url rewriting.

With these two options set. We can now get down to business. Let’s DO THIS!

# Remove www from www.digitaloctane.com
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

The next snippet allows the user to type in a page within our site such as

http://digitaloctane.com/company/about/ this url is then converted by the server to
http://digitaloctane.com/index.php?page=about so instead of having a really ugly url string we can create a new one that is a little bit cleaner and more human readable.

RewriteRule ^company/(\w*+)$  /company/$1/ [R]
RewriteRule ^company/(\w*+)/$ /index.php?page=$1

Lastly we created a very similar implementation for the mobile version of our site (In this example we are NOT doing any mobile site detection. That is being taken care of elsewhere)

RewriteCond %{HTTP_HOST} m.digitaloctane.com
RewriteRule ^(/)?$ /mobile.php [L]

Above we are first defining a Rewrite Condition. If our host is m.digitaloctane.com direct our users to mobile.php.

We can extend this conditional further to allow additional parameters much like the previous example. But for this posting I kept it to the most basic implementation.