Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



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

Posts: 26
Name: Carl
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
carlg is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-18-2008, 06:41 AM Re: mod_rewrite and database
ooyes's Avatar
Skilled Talker

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


RewriteRule /products/([0-9]+) /foobar/products.php?id=$1
__________________

Please login or register to view this content. Registration is FREE
ooyes is offline
Reply With Quote
View Public Profile Visit ooyes's homepage!
 
Old 04-18-2008, 07:09 AM Re: mod_rewrite and database
Average Talker

Posts: 26
Name: Carl
Trades: 0
Thanks,

I guess that means the answer is no.
__________________

Please login or register to view this content. Registration is FREE
carlg is offline
Reply With Quote
View Public Profile
 
Old 04-18-2008, 08:14 AM Re: mod_rewrite and database
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-18-2008, 08:15 AM Re: mod_rewrite and database
andrei155's Avatar
CEO of BLD Hosting

Posts: 1,514
Name: Andrei
Location: Canada
Trades: 6
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
__________________
No Overselling Guarantee
Now Includes a Free Domain
BLD Hosting -
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Last edited by andrei155; 04-18-2008 at 08:16 AM..
andrei155 is offline
Reply With Quote
View Public Profile Visit andrei155's homepage!
 
Reply     « Reply to mod_rewrite and database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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 1.32253 seconds with 12 queries