Line By Line Explanation Of
The .htaccess File
Appendix I –
<IfModule mod_rewrite.c>
This makes sure that mod_rewrite, the internal program that
controls the redirect functionality, is available. If your host
doesn’t allow it, find another host.
RewriteEngine On
This turns the mod_rewrite program on.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond checks to see if something is true about the
request, which for our purposes is the URL that was clicked,
meets certain conditions. If the condition is met it continues
on, if not, the process stops and the URL is processed as
is.
%{REQUEST_FILENAME}
This is evaluating the non-domain portion of the URL. So if
the URL was:
http://www.somesite.com/adirectory/adirectory/afile.html
REQUEST_FILENAME is looking at
adirectory/adirectory/afile.html
!-f
The condition is true if the REQUEST_FILENAME is not an
existing file on the web server.
RewriteCond %{REQUEST_FILENAME} !-d
This is evaluating the condition that REQUEST_FILENAME is
not an existing directory on the web server.
So if the URL points to an existing file or an existing
directory then nothing is done and the mod_rewrite program lets
the URL go as if the .htaccess file didn’t
exist.
This ends the mod_rewrite section of the .htaccess
file.
Now we can put the single line of text that will magically
turn your make believe link into a valid URL and send it off to
the web page you want, and get properly credited if it is an
affiliate link.
It is very important that the new line of text be placed
between the last REWRITE_COND and the line.. It’s also
important to note at this time that the domain must be your
real domain; it is only the directories and file names that can
be make believe.
For this example we will say your domain is www.somesite.com, and you have
the .htaccess file in the root directory (the very top of your
web site structure).
We’ll use the example affiliate link from the first part of
this e-Book as the destination URL:
http://www.lynxtrack.com/afclick.php?o=0000&b=5szt79sm&p=0000&l=1
On our site, and anywhere else we can place affiliate links,
we want the link to be:
http://www.somesite.com/mygreatestoffer
Here is what the .htaccess file will look like (the new line
is high lighted):
# BEGIN
RewriteEngine On
RewriteRule ^mygreatestoffer(/)?$ http://www.lynxtrack.com/afclick.php?o=000&b=5sz [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# END
Let’s look at this piece by piece.
RewriteRule
This tells the mod_rewrite program to evaluate the next
piece and if it matches to rewrite the
URL.
^mygreatestoffer(/)?$
This is what RewriteRule is trying to match.
The ^ means to look at the beginning of the requested
filename, everything after .com/ in this example.
It then looks for mygreatestoffer. The (/)? says to look for
0 or 1 instances of the / symbol. The reason for this is to
catch accidental postings of http://www.somesite.com/mygreatestoffer vs.
http://www.somesite.com/mygreatestoffer/ .
The $ says there should be nothing else after the tested
string. Without it the file request could be mygreatestoffer01
or mygreatestoffer/evenbetter and it would still work. If you
are comfortable with that leave the $ off.
The http://www.lynxtrack.com/afclick.php?o=000&b=5sz is
the URL you want the user to end up at. A Hydramedia offer in
this case.
The [L] Tells the mod_rewrite program to stop processing and
go to the provided URL.
Looking for Great Products to Use & Resell?
Check these Sponsors
http://only4bucks.com
New Private Label or Master Resell Rights
Products Every Week
http://viralbeast.com
Fresh New PLR Products
http://sparechangeprofits.com
THE Wholesale Source for Product Resellers (It’s
where they get their stuff).
|