1

I am trying to set up clean URL's on my small web app. Right now the URL's look like:

http://www.mysite.com/productinfo.php?product=19

I want them to be:

http://www.mysite.com/productinfo.php?product=Shoes

How would I write both the RewriteMap and the PHP script to pull the title column in the database and inject it in the URL in place of the product ID and forward visitors on their merry way?

A Stubbs
  • 11
  • 1

2 Answers2

1

Well in this case, it doesn't look like you're going to need a URL rewrite, since you're just using the same $_GET variable.

Just check for the right title in the database when you interpret $_GET['product'], and find the right product id from there. I don't think you need Apache to solve this problem.

element119
  • 7,475
  • 8
  • 51
  • 74
  • 1
    @A Stubbs, you need to decide what you are trying to do here. If you want SEO-style URIs then you need your app to decode `/product/Shoes` and HTTP server isn't going to help here. – TerryE Mar 22 '12 at 21:52
  • That's why I did a +1, but just paraphrasing for the OP ;-) – TerryE Mar 22 '12 at 22:13
0

You can use a simple rewrite like this -

RewriteEngine On
RewriteRule ^product/info/.*$ productinfo.php [NC,L]

in an htaccess file, vhost or other config and then use -

$var = $_SERVER['REQUEST_URI'];

to retrieve the original request. This is only a very simple example but it should get you moving in the right direction.

user1191247
  • 10,808
  • 2
  • 22
  • 32