pf » Generic Search Engine Safe URL's on Apache

Generic Search Engine Safe URL's on Apache

linux

A while back someone asked about implementing generic search engine safe url's with Apache's mod_rewrite module. I came up with a solution but I didn't have a chance to test it until recently. What I mean by generic are URL's such as: site.com/page.cfm/id/123 and NOT site.com/page/132, which would be specific to just one CFM template. So we only need to create the rules once. This is nice for sites with lots of templates because you don't need to create a rule for each template. Here's what you need to add in your Apache config:

RewriteEngine On
#with one url param
RewriteRule ^/(.*)\.cfm/([^/]+)/([^/]+)$ /$1\.cfm?$2=$3 [NE]
#two url params
RewriteRule ^/(.*)\.cfm/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /$1\.cfm?$2=$3&$4=$5 [NE]

That code will work for up to two url variables, eg page.cfm/id/1/sort/price, if you need to support more you can just add additional rules. This can also work for php, jsp or whatever extension you want, just replace cfm with your extension.


12 people found this page useful, what do you think?

Trackback Address: 96/A623C45B4D937F78ACB2803CA2C437E8
On 02/23/2004 at 2:42:44 PM MST istankov wrote:
1
that's very nice, but what to do when your ISP don't give you chance to edit appache config file

On 06/24/2005 at 9:41:48 AM MDT Pete Freitag wrote:
2
If your host doesn't allow you to change apache config files you may still be able to do this in a .htaccess file.

There are some coding methods to do this as well, see: http://www.petefreitag.com/item/31.cfm

On 09/14/2006 at 1:30:25 PM MDT Morgan Freeman wrote:
3
Congratulations on a great web site. I am a new computer user and finding you was like coming home. Continued success.

On 09/26/2006 at 9:04:28 AM MDT Lion Eve wrote:
4
Let it be, let it be... What a strange place here.

On 06/23/2008 at 1:55:54 PM MDT nansey wrote:
5
4fp7Ed dfv814t4fdfvmlfn093fvgbos




  



Spell Checker by Foundeo





Subscribe to my RSS Feed: solosub RSS
Tags