Forum Moderators: coopster & phranque

Message Too Old, No Replies

How to convert dynamic URLs to static URLs?

Neither mod_rewrite nor environment variables work...

         

MichaelBluejay

2:04 am on Dec 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to convert my urls from this:

 http://domain.com/cart.cgi?333 

to this:

 http://domain.com/333 

where "333" is the item number of a product.

First I tried mod_rewrite:

 RewriteRule ^cart/* cart.cgi?&$1 

The page gets redirected and the browser url stays the same, but my cart.cgi script thinks that QUERY_STRING is empty.

So then I thought I'd just get the entire url using PATH_INFO and then parse it, but when I try my script thinks PATH_INFO is empty no matter what. If I turn off mod_rewrite and then type this into my browser:

[domain.com...]

my script prints the word "test" but not the url, using this code:

[red] $variable = $ENV{'PATH_INFO'};
print $variable;
print "test";
[/red]

Any ideas? Thank you very much for your help.

IanKelley

7:55 am on Dec 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Mod rewrite will work fine, you're just typing waaay too fast :-)

First, the example you gave is:
domain/333

While your rewrite rule implies:
domain/cart/333

Second, you're not capturing anything to $1, use ()'s for that.

Third, * all by itself is not going to produce the outcome you're looking for.

Fourth, you're sending your script data it can't understand:
?&$1

It should be:
?$1 or?something=$1

You'll find no shortage of mod_rewrite examples floating around this and other forums, one of which will do what you want... but I'd recommend actually reading about mod_rewrite and regular expressions so you understand how they work.