Rewrite - same path

Sorry, i thought that this would work, but it doesnt!:slight_smile:

…but in principle, should it function?


rewriteRule ^picture-frames/([^.]+)$ /familes2.php?fam1=$1&lang=en [NC,L]
rewriteRule ^picture-frames/([^.]+)/([^.]+)$ /diagram2.php?fama=$1&cola=$2&lang=en [NC,L]

Ive tried pictureframes/one/two for example and it keeps pointing to familes2.pp rather than diagram2.php

…any thoughts…thanks in advance

Hi barney. It seems ok, but with just that info…

is the fama correct in line 2? If it were incorrect, would the “bad” url be redirected to family.php? I noticed it’s fam1 in the first one.

I’d take the first rule out (or comment it out) first to make absolutely sure the second url-type isn’t still somehow getting caught in the first match. So, line 2 by itself-- does it go to diagram2.php?

You don’t need or want the NC flags on these. FAM and fam are and should be two totally different things on your server. NC is good to have for your domain name {HTTP_HOST} etc, but not your inner files. (has nothing to do with your error, it’s just a note)

I was just about to do another post based on my findings, then i got your reply!

I deleted the first rewrite…

when i tried
website.com/picture-frames/Classics/Brushed-Gold-and-Silver

… it went to diagram2.php and passed the variables ok.

I then tried

website.com/picture-frames/Aluminium

…which obvioulsy failed as there was not a rewrite rule

So now im confused…any thoughts how i can test/edit further?

(From your post - i just tried fama/fam1 as a test)

well, really weird…and a bit nervous about its accuracy, but i simply changed the order of the rewrite

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewriteRule ^picture-frames/([^.]+)/([^.]+)$ /diagram.php?fam1=$1&col1=$2lang=en [NC,L]
rewriteRule ^picture-frames/([^.]+)$ /familes.php?fam1=$1&lang=en [NC,L]
</IfModule> 

I think your first rule was catching everything, is all. Your rewrite rule excludes dots, but not slashes:
^picture-frames/([^.]+)$
that does indeed match /picture-frames/Classics/Brushed-Gold-and-Silver

maybe originally you were thinking ^picture-frames/([[1].[/color]/]+)$
where that last atom means any characters who aren’t dots or slashes? 'Cause in /picture-frames/Classics/Brushed-Gold-and-Silver, “Classics/Brushed-Gold-and-Silver” match your ([^.]+)$ 'cause they indeed are “one or more non-dots”.

So it was already getting matched before it even got to your second rule.

Notes:

-remove the <FfModule> tags. If you didn’t have the module mod_rewrite, your rewrites wouldn’t work. So having IfModule tags aren’t helping you stop Apache from puking, because you DO have mod_rewrite, Apache won’t puke, and you’re just making it spend lots of extra time and cycles checking to see that you have mod_rewrite before running your rules.

-remove the no case flag [NC]. Keep the [L] flag, tho I’m not sure you need it after the first rule, since after the url’s been rewritten, it won’t match the next rule either way. Do keep it on the second rule tho.

I see now that both url’s are fam1. I didn’t know if those were supposed to be different or not, just mentioned that I noticed they were different originally. Sometimes a Rewrite doesn’t work and it’s not that the rewrite rules themselves were bad, but that there was just a typo somewhere.


  1. color=red ↩︎

Thanks for your help and the time spent to explain further…

It came down to missing ‘/’…ive put the order back as in the original and it works fine.

The IfModule tag was a left over from another old htaccess file…on one italian server there are numerous problems that i had to bung in loads of extras just to get it to work…

b

barney,

Good explanation (and complaint about the <IfModule> and [NC] bits - that saved you from my typical ranting about those! :smiley: ) from StommePoes.

As demonstrated, when you use “lazy regex” (generally (.*) but ([^.]+) is a close cousin), ORDER of your mod_rewrite statements can be critical!

IMHO, you would benefit from a read of the mod_rewrite tutorial linked in my signature - if nothing else, it’ll definitely cure your insomnia!

Regards,

DK

IMHO, you would benefit from a read of the mod_rewrite tutorial linked in my signature - if nothing else, it’ll definitely cure your insomnia!

I suppose you could say that about most specs. I find the HTML specs are great bedtime reading.

Luckily you werent around yesterday…as you usually shoot me down! :wink:

Yesh, I’m a sweetie : )

Just wait, when my carpel tunnel kicks in, I too will become crusty and irascible. Everything will start out with “Arg, kids these days… get off my lawn!”

: )

barney,

Aw, you love the attention! :lol:

Okay, maybe not but I trust that you get the points that I make and have learned something about mod_rewrite (which is my intent). I just want people to learn, not be spoonfed code (I don’t feed “script kiddies”). :blush: Oh, my! There I’ve gone and done it again! :x

Waddya think I wrote that tutorial for? After a year of answering the same questions over and over again, I thought it might prevent carpal tunnel. Silly me! :smiley: Noone reads the darned thing unless I tell them that the code they’re looking for is there … and that takes about as many characters as repeating that section of the tutorial! Talk about frustration (AND carpal tunnel)!

barney, see what you missed! :goof:

Regards,

DK

Noone reads the darned thing unless I tell them that the code they’re looking for is there … and that takes about as many characters as repeating that section of the tutorial!

Which is why you’ll want to program a Macro into your keyboard. You hit reply, hit the one special key, it spits out a pre-written rant and link to sig, complete with little flaming/exploding smilieballs, and submit.

Another option is to create something like an irc bot. You’d call it @AngryLynn or something : ) Just take telephone-company code and shove it in there and change all references to $phone_company to $sigTut.