Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite - Using an external text file/database

         

edward301

11:35 am on Jun 18, 2005 (gmt 0)

10+ Year Member



Currently I have a website with urls in the following format:

http://www.example.com/type1/type.php?id=1 (1-50 with more and more being added)
This page has the title "Type1 - Content title"

I would like to use if possible to use mod_rewrite to change this to
http://www.example.com/type1/Type1-Content-title/

Is it possible to list the urls in a text file with the text that i want the url to become?

eg .htaccess
RewriteEngine on
RewriteRule get list.dat

eg . list.dat (i would use a php script to create/update this file using data from a mysql database)
http://www.example.com/type1/type.php?id=1,Type1- Content-title-One
http://www.example.com/type1/type.php?id=2,Type1- Content-title-Two
http://www.example.com/type1/type.php?id=3,Type1- Content-title-Three
http://www.example.com/type1/type.php?id=4,Type1- Content-title-Four
http://www.example.com/type1/type.php?id=5,Type1- Content-title-Five

or is there an alternative solution?

jdMorgan

3:36 pm on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'd be better off doing this almost entirely within php, since mod_rewrite in .htaccess has no capability to use a RewriteMap.

Also, be aware that you need to output the 'friendly' URL on your pages. When one of those friendly on-page links is clicked or followed by a robot, then the friendly URL will be requested from your server.

Upon receipt of the friendly URL request, mod_rewrite must identify it and rewrite it to your script. The script can then use the friendly URL to look up the local file-path to the correct content and serve it.

Each friendly URL must contain sufficient information so that it can be identified as a URL that needs special treatment. The simplest way to do that is to tag all friendly URLs with a unique prefix, such as "type" or "cat-" or "prod_" or even just "~" -- But you need to provide a key to flag mod_rewrite and your script that the URL will need to be "translated."

To make an important point quite explicit, mod_rewrite is not used to rewrite unfriendly URLs to friendly URLs during the response phase; It is used to rewrite friendly URLs to unfriendly filepaths or script calls during the request phase, before any content is served and before any scripts are invoked. The conversion of unfriendly URLs to friendly URLs must be done by your script or by hand-editing static HTML pages.

A search for "friendly URL RewriteRule [google.com]" will turn up tons of previous discussion.

Jim