Solved

mod_rewrite using corresponding database values

Posted on 2006-07-20
7
280 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 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