Web Hosting Talk







View Full Version : mod_rewrite for dynamic sites to appear static...


digitsix
04-18-2003, 12:32 AM
Im looking for someone that knows mod_rewrite to tell me how I could go about getting a url that is, right now like so...

http://www.domain.com/catalog.php?c=3&p=123&id=3

to something like...

http://www.domain.com/catalog/c/3/p/123/id/3.html

I know it can be done, but im lost at how to do this, I already read the mod_rewrite docs and I'm still lost....

someone please help!

digitsix
04-18-2003, 02:30 AM
I figured this much out:

RewriteEngine On
RewriteRule ^/test/catalog/c/([0-9]+)/p/([0-9]+)/id/([0-9]+)$ /test/catalog.php?c=$1&p=$2&id=$3

Now when i go to http://www.domain.com/test/catalog/c/3/p/134/id/3 it does in fact redirect me to catalog.php but the values for some reason are still not filled in....

any help?

DarktidesNET
04-18-2003, 03:29 AM
I think you have to have something like [PT] on the end.

I've really had no luck with mod_rewrite either.

sponk
04-18-2003, 12:53 PM
try this


RewriteEngine On
RewriteRule ^/test/catalog/c/([0-9]+)/p/([0-9]+)/id/([0-9]+)$ /test/catalog.php?c=$1&p=$2&id=$3 [L]

digitsix
04-18-2003, 02:06 PM
I tried both things and neither of them worked, thanks for trying though.... anyone else have any ideas?

wakkow
04-18-2003, 02:08 PM
I don't know mod_rewrite very well... but, i'll try anyways.. what do the two you tried do/not do? Not fill in the variables?

sponk
04-18-2003, 07:26 PM
ok, try putting in the full URL

RewriteEngine On
RewriteRule ^/test/catalog/c/([0-9]+)/p/([0-9]+)/id/([0-9]+)$ http://www.yourdomain.com/test/catalog.php?c=$1&p=$2&id=$3 [L]

I did that for mine and it worked

DarktidesNET
04-19-2003, 12:07 AM
If it requires the full url, it could be an issue of a shared IP vs. Dedicated.

Just a hunch

digitsix
04-19-2003, 04:59 AM
I tried the whole url and it still does the same thing. As it stands right now, it does in fact send me to the correct php file when i go to the fake string (the one with all the slashes)... but for some reason the c, p, and id variables are null..., I even have an echo line at the top of the catalog.php file that echos out the variables... mod_rewrite should send these variables in the environment right? I mean, that is the point of puting the $1 $2 and $3..... that would be my guess anyway... its just, im currious, how does it know what to put in the $1 $2 and the $3? I dont see how it would know to use the regex sections between the /'s as the variables....

I DONT UNDERSTAND!!!!!!!

DarktidesNET
04-19-2003, 05:02 AM
I'd assume it got the variables filled from the regex via back referanncing (the grouped (items)) are filled.

That's how you grab data from regular expressions by grouping them with () like a+([a-z]) you'd get the [a-z] value not the whole string.

digitsix
04-19-2003, 03:30 PM
Well, i figured out that mod_rewrite isnt forwarding anything at all, somehow the server is just guessing i mean catalog.php when i put catalog/whatever i want.....

So i made a new rule, a very simple one...

RewriteRule ^/cata/(.*) /catalog.php?c=$1

and when i go to www.domain.com/cata/123

instead of going to catalog.php?c=123 i get a 404 not found cata no such file or directory...

This is odd to me because I have the .htaccess in the right directory, and in the server config for this directory, it has allow override set to all... If i had a gun, ida shot my self by now, so some one please, for the love of god, help me... i have no clue what the hell to do next.

Mod_rewrite IS installed...