A list of htaccess Tutorials

First off, here are a few samples. The first thing you will need to do is add these two lines at the top of your .htacccess file:

Options +FollowSymlinks
RewriteEngine on

RewriteRule:
Say you’ve change from using html files to dynamic PHP files. Instead of changing your nav links to point to php files, you can force all url path that end with .html to .php like so:

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

RewriteCond (Rewrite Condition)
If you have query string in the page and you want them to be carried over to the new page, you have to set a rewrite condition for query strings. The example below first sets the query condition in line one and than redirects from one web page a new web page using in line two. It uses this bit of text “(.+)” to grab the query and “%1” to pass it to the new page:

RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^webpage.php /new_webpage.php?%1

Convert url directory paths to a query string.
RewriteRule (.*) /index.php?paths=$1

Convert url directory paths to a query string using custom folder paths.
This one only does it if you’re under directory “sell”. So if users are under “/sell/computers/mac/”
you can send “computers/mac” as the category and do a split on the “/” slash to seperate them.
RewriteRule ^sell/(.*) /sell.php?category=$1


ErrorDocument :
Here’s how to customize or ignore your error messaging. You can do this by targeting a file like this:

ErrorDocument 404 /dir/home.html
ErrorDocument 403 /custom_error_message.html

Here are a few more site I found helpful.

Custom HTTP Errors via htaccess:
http://perishablepress.com/press/2008/03/18/custom-http-errors-via-htaccess/

Custom dynamic redirecting and rewriting
http://corz.org/serv/tricks/htaccess2.php

Leave a Reply