Solved

mod_rewrite using corresponding database values

Posted on 2006-07-20
7
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

632 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