.htaccess
Turn Off PHP Parsing In A Directory
Tue, 12/23/2008 - 15:24 | by philipnorton42Sometimes it is necessary to turn off PHP parsing for a directory. You might want to give away some source code and therefore don't want to parse that code when the user tries to download it. You could just rename the file to have the extension .phps, which is a PHP source file, but this is an alternate method.
To turn off PHP parsing in a directory just create a .htaccess file with the following content.
php_flag engine off
You can expand on this by adding the following:
Some .htaccess Rules To Improve PHP Portability
Fri, 12/05/2008 - 11:13 | by philipnorton42PHP is a powerful tool, but if you create any piece of software there are one or two things that you should never rely on.
A good example is using PHP short tags. This is a short hand way of stating that this block are to be parsed as PHP. This is an example of a normal tag.
<?php echo 'Hello World'; >
Here is the same code using short tags.
Redirect One Directory To Another With .htaccess
Mon, 05/19/2008 - 08:55 | by philipnorton42To stop access to a directory (and anything in that directory) all you need is a simple RewriteRule.
RewriteEngine on RewriteBase / RewriteRule ^exampledirectory/(.*)$ / [R=301,L]
In this example, if this .htaccess file resides in the root directory of the site and you try to access anything within /exampledirectory you will be redirected back to the root folder. To redirect to another folder (like anotherdirectory) on your web server use the following rule.
When To Use .htaccess Files
Thu, 05/01/2008 - 08:45 | by philipnorton42Hypertext access, or .htaccess files, allow you to change the Apache configuration on a by directory basis. However, you should always use the main server configuration file to do configuration changes whenever possible. This is because when Apache is configured to process .htaccess files it looks at every directory underneath the current directory to see if there are any files present, resulting in a slightly longer page load time. Although this might not be noticeable with low traffic levels, at high traffic levels it can cause sites to slow down.
Preventing Image Bandwidth Theft With .htaccess
Mon, 04/21/2008 - 08:43 | by philipnorton42When people link to your images from their own site they are essentially using your bandwidth to show images on their site, this is also known as hotlinking.
The simplest way of preventing people from doing this is to add a .htaccess file to only allow locally linked images to be served. This checks the domain that is linking to your images by using the referrer and if the domain does not equal you own site then a different image is served, in this case blank.jpg.
Using mod_rewrite On Form Parameters
Wed, 03/05/2008 - 12:42 | by philipnorton42Using mod_rewrite on websites is fairly straightforward and can create some lovely looking URL structures. Instead of having a URL that contains lots of odd looking parameters like this:
http://www.example.com/example.php?parameter1=value1¶meter2=value2
You can use a .htaccess file to rewrite the URL on the server side in order to shorten this to something like this: