Solved

mod_rewrite using corresponding database values

Posted on 2006-07-20
7
277 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
Comment Utility
In your .htaccess file

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

Expert Comment

by:rhickmott
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Bueller? Bueller?

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

Accepted Solution

by:
caterham_www earned 400 total points
Comment Utility
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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.

744 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

15 Experts available now in Live!

Get 1:1 Help Now