Digital Handyman
 
   
  Digital Handyman<-->
msgbartop
Resourceful problem solving in a digital world
msgbarbottom

Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 35

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 43

Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 35

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 43


Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 35

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 107

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 109

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 111

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/sites/andrefredette.com/blog/wp-includes/functions.php on line 112
02 Nov 08 Renamed Folders and mod_rewrite

Apache’s mod_rewrite is one of the most confusing things to learn but it is an extremely powerful tool. One of the best resources I found was http://www.webforgers.net/mod-rewrite/. Recently I needed to rename a folder on one of the sites I built. The traffic needed to be automatically routed to the new folder to keep all the links to the content valid. To accomplish this, i used a mod rewrite to grab the string after the old folder and move it to the new folder. Below is the content of my .htaccess (located in the root directory with my new folder) file:


RewriteEngine On
RewriteBase /subdir/
RewriteRule ^olddir/?(.*)$ newdir/$1 [R=301,L]

So lets look at it line by line

RewriteEngine on

The RewriteEngine has to be on (obviously).

RewriteBase /subdir/

the RewriteBase is the path to the folder containing your .htaccess and the new folder (in this case, “subdir/” would contain “.htaccess and newdir/”). This is relative to the domain. So if you were working with yourdomain.com/newdir/ the RewriteBase would just be “/”.

RewriteRule ^olddir/?(.*)$ newdir/$1 [R=301,L]

The RewriteRule takes anything after the request for your old folder (like index.html) and changes the URL to the new folder. “olddir” is the name of your old folder and “newdir” is the name of your new folder. So a request like:

yourdomain.com/subdir/olddir/index.php?var=value

would become

yourdomain.com/subdir/newdir/index.php?var=value

it doesnt matter what comes after the request for the oldir it will get moved to the newdir. It’s pretty obvious that mod_rewrite is a powerful tool but mastering it is a significant challenge. Here’s one down though, and plenty more to go.

-Dre

Tags: , ,