![]() |
|
|
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 |
|
|
|
| Sponsored Links (We share ad revenue): |
|
|
Re: mod_rewrite and database |
|
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 |
|
|
|
|
|
Re: mod_rewrite and database |
|
Average Talker
Posts: 21
Name: Carl
|
Thanks,
I guess that means the answer is no. |
|
|
|
|
|
Re: mod_rewrite and database |
|
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!!!" |
|
|
|
|
|
Re: mod_rewrite and database |
|
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 ![]() Last edited by andrei155 : 04-18-2008 at 07:16 AM. |
|
|
|
| Sponsored Links (We share ad revenue): |
| Thread Tools | |
|
|
| Webmaster Resources Marketplace: |
| Software Development Company | Webhosting.UK.com |
| Web Templates | Text Link Brokers | Stock Photos |