One of the bonuses of attending the WMW Pubcon is that they mail attendees a cd of all of the PowerPoint presentations that were used in the sessions. One of the presentations was by a company called TrueLocal, where they discussed using mod rewrite for various things. Now, I do not claim to have much knowledge about mod rewrite, so I cannot explain any of the code they showed us. But, I thought you might like to have the code in case you need it. So, without further explanation, here it is.

Folder move (redirect) - moving a folder from an old location to a new one:
RewriteRule ^olddir/(.*)$ /newdir/$1 [R=301,L]

Serving content transparently - shortening urls for search engines
RewriteRule ^([^/]+)/(.+)$ /file.php?Dir=$1&file=$2 [L]

Deny access to an IP:
RewriteCond %{REMOTE_ADDR} ^123.45.67.[9]$
RewriteRule ^/.* - [F]

Serve Different Content to a UA/IP:
RewriteCond %{HTTP_USER_AGENT} ^Jakebot
RewriteRule ^page1.html$ /special-page.html [F]

Serve Image Based Upon Referrer - Prevent image theft:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !.*/valid-page.htm
RewriteCond %{REQUESTED_FILENAME} ^specific-image-name.jpg$
RewriteRule .*.(gif|png|jpe?g) https://www.example.org/funnypic.jpg

Please make sure you backup your .htaccess file before adding this code to it, in case you need to revert back.

About the Author: Donna Fontenot

Donna Fontenot, aka DazzlinDonna, is an Internet Entrepreneur and SEO, who has long utilized search engine optimization and affiliate marketing to create a successful online business. Her goal as an ebusiness coach is to help others make a living online from the comfort of their homes (and in their pajamas). Her motto is "You'll never shine if you don't glow."

One Comment

  1. Joe Poniatowski November 25, 2008 at 11:15 am

    Thanks for the tips, Donna. Hopefully I’ll be able to use them.

Comments are closed.