Solved

mod_rewrite using corresponding database values

Posted on 2006-07-20
7
281 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

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!

Question has a verified solution.

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

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 your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

680 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