Mod rewrite Tutorials

overview - syntax - basic - medium - advanced

Mod Rewrite Basic tutorials

The majority of you came to this site to find out how to do one of these basic tutorials. So lets go ahead and line up what we'll be learning.

Tutorial 3
File and file Extension rewrites

These rewrites in this tutorial are helpful when you are changing old static .html files into a more dynamic server side scripting file like .asp, .jsp, .cfm or .php. Some of these also fall under the "if I did this it would look cool" category. Enjoy!

Scenario 1:
We have a dynamic site using .php extensions. We just want to make the site look less dynamic and more like hand made. All the file names are staying the same, we just want to change the extensions to .html.

.htaccess code RewriteEngine On
RewriteBase /

RewriteRule ^(.*)\.php $1.html [R=301,L]

RewriteRule ^(.*)\.html $1.php [L]

Like in tutorial 2 when we change files we need to use a 301 to point users and search engines to the new files. The first rewrite rule will do the redirect to the new files.

The second rewrite rule will call the .html's matching php file as an alias. Think of the file alias as allowing you to substitute any file you want on the server. In our case we're going to substitute somefile.php for somefile.html. We get all the dynamics from a .php file and the user has no clue at all.

Practical uses for scenario 1

  1. To change your file extensions smoothly.
  2. To alert search engines to updated files on your site.

Scenario 2:
We own a music store online. For our cd catalog online we want to change the file extensions from .php to .cds. We think users will get a laugh if the call up the file /catalog/metalica.cds .

First we'll have to change our files to out put a .cds instead of .php. Then all you need is this code

.htaccess code RewriteEngine On
RewriteBase /

RewriteRule ^catalog/(.*)\.php catalog/$1.cds [R=301,L]

RewriteRule ^catalog/(.*)\.cds catalog/$1.php [L]

Ok I know it's redundand but I know people want to know how to do this. I'm sure any of you porno boys that learn this rewrite will have fun. I'm sure your visitors will think you're the bomb when they show up to your site tomorrow and all your file extensions have been changed to .xXx .

Practical uses for scenario 2

  1. To look cool to your customers
  2. Come on I know you hacker boys would get a blast out of changing a victims file extensions to .dork or worse. Though this isn't very practical it would sure be funny to find cnn.com hacked and all it's extensions changed to .fox .

 

<< mod rewrite syntax :: basic mod rewrites :: medium mod rewrites >>

Questions that are answered here:

  • What is a mod rewrite?
  • What can a mod rewrite do?
  • How do I rewrite my messy urls
  • How do I make clean urls

On Page Resources

  1. Non commercial Application - These are dynamic pages that you, your developers, free lancers or kid brother have written.

  2. 302 Page Hijack - There are 2 files involved with a page hijack. The hijacker file and the hijackee file. The hijacker is the file the sends the 302 redirect. the hijackee is the file that gets hijacked.

    The hijacker file will inherit the search result title and description. It will also show the cache of the hijackee.

    The hijackee will not know anything has happened until the owner of the hijackee file checks for the file in the search engines and cannot find it.

 

Mod Rewrite (Home) | Mod Rewrite Tutorials | Directory | Code Library | Blog | Mod Rewrite Quick Guide

copyright © 2001 - 2009 Webforgers.net
Owned By SEO Uncloaked, LLC
Aggressive Search Engine Optimization
All rights reserved.