Search Engine Friendly URLs

Search Engine Friendly URLs with ForceType

Implementation:

The ForceType method works very similarly to the PATH_INFO method except it adds one additional layer of complexity because you are now hiding the extension of your script so that it looks like a directory.

Typically a web server knows how to handle requests by the extension any given file has. For instance, if a file has a .php extension Apache knows to parse it for PHP code before sending it to the browser. Apache's ForceType directive allows you to override any default mime types you have set up. Usually it may be used to parse an .html page as php or something similar, but in this case we will be using it to parse a file with no extension as php.

So instead of using article.php, as we did in method 1, rename that file to just "article" with no extension. You will be able to access it like this: http://www.domain.com/article/999/12/. Utilizing Apache's look back feature and $PATH_INFO variable as described in method 1. But as of right now Apache doesn't yet know to that "article" needs to be parsed as php. To achieve that you must add the following to your .htaccess file.

<Files article>
ForceType application/x-httpd-php
</Files>

This is known as a container. Instead of applying directives to all files Apache allows you to limit them by filename, location, or directory. You need create a container as above and place the directives inside it. In this case we are using a file container, we identify "article" as the file we are concerned with and then we list the directives we want applied to this file before closing off the container.

With the directive inside the container we are telling Apache to parse "article" as a php script even though it has no file extension. This allows us to get rid of the period in the URL that causes the problems yet still use the PATH_INFO method to manage our site.

Troubleshooting

The trouble shooting issues for this method are exactly the same as for method #1.

Drawback:

There aren't really any drawbacks to doing this, this is one of the best methods of achieving friendly URLs, and in fact is probably my favorite method. It is also the method utilized on this site.