Reply
mod_rewrite and database
Old 04-17-2008, 09:53 PM mod_rewrite and database
Average Talker

Posts: 21
Name: Carl
Is it possible to use mod_rewrite with a database?

For example:

I want to transform the following url:

www.mysite.com/detail.php?productid=12

to the following url

www.mysite.com/cordless-drill/

Where "cordless-drill" came from the database by doing a lookup on id # 12.

Is this possible?

Thanks
carlg is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Old 04-18-2008, 05:41 AM Re: mod_rewrite and database
ooyes's Avatar
Skilled Talker

Posts: 54
Name: Web Design Company
Location: London
Actually the mod_rewtire has nothing to do with databases it just overwrites the URL


RewriteRule /products/([0-9]+) /foobar/products.php?id=$1
__________________
Website design
ooyes is offline
Reply With Quote
View Public Profile Visit ooyes's homepage!
 
Old 04-18-2008, 06:09 AM Re: mod_rewrite and database
Average Talker

Posts: 21
Name: Carl
Thanks,

I guess that means the answer is no.
carlg is offline
Reply With Quote
View Public Profile
 
Old 04-18-2008, 07:14 AM Re: mod_rewrite and database
tripy's Avatar
Fetchez la vache!

Latest Blog Post:
Pretty pretty please….
Posts: 1,689
Name: Thierry
Location: In the void
it's no in the sense that mod_rewrite is just a transformation engine.
It cannot query a database to translate something in another thing.

But, if those are not going to change, you can define a lookup table, or rewrite map.
Look at the official mod_rewrite reference:
http://httpd.apache.org/docs/2.0/mod...tml#rewritemap

or in this thread for a real life exemple:
http://www.webmasterworld.com/forum92/1639.htm
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-18-2008, 07:15 AM Re: mod_rewrite and database
andrei155's Avatar
CEO of BLD Hosting

Posts: 389
Name: Andrei
Location: Canada
it IS possible, as long as your first URL remains constant.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ search.php?terms=$1 [L]

This rule set internally rewrites all requests that do not exist on the server as a file or directory to a search script that has access to the non-existen request via the query string by testing each request against the request's system filename. %{REQUEST_FILENAME} is a server variable containing "the full local filesystem path to the file or script matching the request" (eg, /home/foo/public_html/find in the first example). -f tests the %{REQUEST_FILENAME} to see if it's an existing file; -d tests to see if it's a directory. The exclamation point negates the tests.

This is commonly requested as a way to catch all non-existent requests instead of sending the normal 404 Not Found server error.

http://forums.devshed.com/showthread...61#post1165161
- wonderful link if you want to know more about mod rewrite

Edit:
Sorry tripy, looks like we posted at the same time
__________________
BLD Hosting - Shared: As low as $2.00! Reseller: As low as $4.00

Web Hosting

Last edited by andrei155 : 04-18-2008 at 07:16 AM.
andrei155 is offline
Reply With Quote
View Public Profile Visit andrei155's homepage!
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to mod_rewrite and database
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.14783 seconds with 14 queries