Solved

mod_rewrite using corresponding database values

Posted on 2006-07-20
7
278 Views
Last Modified: 2010-03-04
I know the basics of doing mod rewrites but am wondering how the following would be accomplished. let's say we have this URL:

http://www.website.com/productdisplay.php?category=1&product=654&color=4

I know how to get it to rewrite to www.website.com/1/654/4.html but that doesn't do squat for SEO purposes. The corresponding values to the numerals have to be inserted based on database values so that www.website.com/widgets/nose_trimmer/blue.html is actually displayed. And, BTW, it is a MS SQL database since we're running Apache2.2.2/PHP5.1.4 on a W2K server (don't ask....)

So the mod rewrites have to check what "1", "654" and "4" represent befor the URL can actually be rewritten. Can that be done from the .htaccess file?

0
Comment
Question by:cbeaudry1
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 17147554
In your .htaccess file

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^\.]*)\.html$ productview.php?category=$1&product=$2&color=$3 [L]
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 17147596
Oh sorry just read the question again.

Im not aware of anyway of getting .htaccess to check a Database maybe an extemply hacky MS SQL Apache Module (if one has been written) could you not rewrite http://www.website.com/widgets/nose_trimmer/blue.html to http://www.website.com/productdisplay.php?category=widgets&product=nose_trimmer&color=blue then get the corrosponding PHP script to look up the values (not effcient I know)

0
 

Author Comment

by:cbeaudry1
ID: 17147712
I know the rewrite rule parameters your had in your first answer. Doing rewrites based on the second answer wouldn't work because we'd have to add a new rule everytime a product or category or color is added. Doesn't make sense...

Unless there's a way to do it, a major rewrite of the shopping cart's navigation is the only way I see out of this dilemna.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 100 total points
ID: 17147877
Well I was thinking more of a rewrite of

http://www.website.com/widgets/nose_trimmer/blue.html to http://www.website.com/productdisplay.php?category=widgets&product=nose_trimmer&color=blue

then in productdisplay.php do a query based on category SELECT `CATEGORYID` WHERE NAME = 'widgets' etc and extract the numerics out that way.

But I agree it would mean using unique colors, product names and category names or using text primary keys.
0
 

Author Comment

by:cbeaudry1
ID: 17201144
I still don't have a workable solution for this. As an example, you can see how story URLs are displayed on CNN. I'm sure that the actual directory structure of the site is not what you see in those URLs. They are undoubtedly pulling URLs that use numerical record numbers and using a rewrite to achieve the URLs you see. I need something similar.

Example:

http://www.cnn.com/2006/WORLD/meast/07/27/zawahiri.tape/index.html
0
 

Author Comment

by:cbeaudry1
ID: 17318489
Bueller? Bueller?

There's gotta be a way of doing this, no?
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 400 total points
ID: 17320601
Write a RewiteMap program (prg:) or use your php script to perform database lookups and to get your IDs as mentioned already above. There can't be a full working solution here, because it's up to your script and database structure how to write and perform such lookups.

The rewrite construct with a Rewritemap in your <virtualhost...> might look like this

RewriteEngine on
RewriteMap lookupmap "prg:C:/Perl/bin/perl.exe C:/map.pl"
RewriteRule ^/(.*)\.html /${lookupmap:$1} [L]

So your map script gets widgets/nose_trimmer/blue as input and must return productdisplay.php?category=1&product=654&color=4
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now