Forum Moderators: phranque

Message Too Old, No Replies

need to know if my URL can be mod rewritten?

         

marcus76

11:11 am on Apr 24, 2007 (gmt 0)

10+ Year Member



hi,

i have the following type of URL:

http://www.example.com/area_id,68/simplesearch.htm

i'd like to replace the 'area_id,68' with the "keyterm" associated with 68 and remove the simplesearch.htm at the end of the URL....

so something like this.

http://www.example.com/keyterm.htm

I do have several thousand of these however - can someone please advise a way to do the above without listing the several thousand entries in the .htaccess file?

Is it common to list several thousand entries in a .htaccess file?

many thanks

Marcus

[edited by: jatar_k at 11:51 am (utc) on April 24, 2007]
[edit reason] please use example.com [/edit]

jdMorgan

3:12 pm on Apr 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simplest and most manageable/maintainable way to do this involves using RewriteMap to call a script that accesses your existing database to look up the 'real' URL. The database can be expanded to include the 'friendly' URL and it's 'unfriendly' location, if it does not already contain this info. This allows the URL-mapping to be managed from the same interface that you use to maintain everything else. RewriteMap is only available if you have access to the server configuration files such as httpd.conf and conf.d.

Alternately, your main script (whatever script the URL "simplesearch.htm" currently points to) can do this lookup itself. You just use mod_rewrite or AcceptPathInfo to pass control to your script no matter what the "details" part of the friendly URL contains, and let the script take it from there. For example, you might start all your friendly URLs with "example.com/areas/". The "areas" part of the URL is use to tell mod_rewrite to forward the request directly to the script that does the lookup for the requested "area." The script can then extract anything else it might need from the URL, and then look up the actual data it needs from your database.

If you can't modify the main script, then perhaps you can "wrap" it inside another script, which does only the translation, and then passes the needed info to the original script -- There are a hundred ways to skin this cat.

I cannot recommend putting thousands of rewrites or redirects in an .htaccess file.

Jim

marcus76

8:15 am on Apr 25, 2007 (gmt 0)

10+ Year Member



Jim, many thanks for this post - i'll go do some digging - if anyone wants some freelance work i'd be happy to pass this your way.