(another) rewrite question

Hey chaps

Something isnt right…im tired today but that shouldnt be an excuse!

In the htaccess file i have

rewriterule ^Tavoli/(.*)$ /testb.php?cat1=Tavoli&cat2=$1&currentpage=1  [NC,L] 
rewriterule ^Tavoli/(.*)/(.*)/(.*)$ /testb.php?cat1=Tavoli&cat2=$1&test=$2&currentpage=$3  [NC,L] 

When i go to website.com/Tavoli/Rustiche i get directed to testb.php and works fine, when i link from this page to website.com/Tavoli/Rustiche/pages/2 it fails…

in the head of testb.php i have

$cat1a = $_GET['cat1'];
$cat1b = $_GET['cat2'];
$currentpage = $_GET['currentpage'];

In the first rewrite it works fine, however on the second rewrite when i echo out the info for a test i get:

Cat1:Tavoli
Cat2:Rustiche/pages/2
Cat3:
Page:1

i.e 3 variables are grouped together and the page number is incorrect…is it because im directing to the same page that is causing the issue?

thanks in advance

oh, now i understand :slight_smile:

I thought the problem was with the third rule, hence me giving it all my attention…forgetting that because i opened the floodgates for everything on the second rule it all went wrong!

All working now…many thanks for you patience!

Not a problem. Glad you got it working :slight_smile:

Thanks Scallio, however its still not working :frowning:

Ive changed the htaccess and pointed the second link to another page as a test, however its still pointing to testb.php rather than testc.php.

Ive changed cat1 to scat1 just incase there was any conflict with the db entries of cat 1, cat2 etc.

Ive emptied my cache also to see if this was the problem.

This is waht i have at the mo

rewriterule ^Tavoli$ /testa.php?scat1=Tavoli&scat2=moderne&currentpage=1 [L]
rewriterule ^Tavoli/(.*)$ /testb.php?scat1=Tavoli&scat2=$1&currentpage=1  [L] 
rewriterule ^Tavoli/([a-zA-Z]+)/pages/([a-zA-Z\\d]+)$ /testc.php?scat1=Tavoli&scat2=$1&currentpage=$4  [L]

so when i go to http://www.website.com/Tavoli/Rustiche/pages/2
cat2 still outputs 'Rustiche/pages/2

Please read my previous again to see what I said about that :kaioken: ANYTHING :kaioken: atom :slight_smile:
You did it correct in the third rule, but now you’ve made the second rule overly greedy.

Also, a page number doesn’t contain characters, does it? :wink:
Tavoli/([a-zA-Z]+)/pages/color=“blue”[/color] should be Tavoli/([a-zA-Z]+)/pages/color=“blue”[/color]

Nope, the isssue is that you are using the (.*), known as the :kaioken: ANYTHING :kaioken: atom and you fell into its ugly little trap.

The problem is that (.) will match anything and everything, so it just goes on and on matching until there is nothing more to match. In this case it’s also matching the slashes further down the rewriterule, because it’s a real gready bstard and just eats everything it sees…

The solution here is to replace the (.*) with sensible atoms like (\d+) for numbers, ([a-zA-Z]+) for names, etc.

Also, why don’t you match “pages” directly? You know the second part of the URL must be “pages”, so you might as well set that.

As a start


rewriterule ^Tavoli/[COLOR="Red"](.*)[/COLOR]$ /testb.php?cat1=Tavoli&cat2=$1&currentpage=1  [L] 
rewriterule ^Tavoli/[COLOR="Red"](.*)[/COLOR]/[COLOR="RoyalBlue"]pages[/COLOR]/[COLOR="RoyalBlue"](\\d+)[/COLOR]$ /testb.php?cat1=Tavoli&cat2=$1&test=$2&currentpage=$3  [L]

I have no idea what the possible values are for the second part of the URI (your example indicated “Rustiche”), so I can’t give you the appropriate atom for that. If it contains only characters you should use ([a-zA-Z]+), if it contains characters and/or digits you should use ([a-zA-Z\d]+), etc.

Lastly, the [NC] is only needed when you need to match a domain name, since you have no control over how users type that (some may type example.com, others ExamPle.com, etc). However, since you control what your URLs look like it is your job to specify the correct atoms.

Hope that helps :slight_smile: