Rewritting urls

I have a site where I want all the url like:
www.sitio.com/city/category/nombreitem
I made a friendly url that are running when I have not chosen any city in a scrolling list of cities on my site.
The rules are:

RewriteRule     ^(.*)/(.*)/(.*)/(.*)?$                    /index.php?city=1$&ct=$2&md=details&id=$4 
RewriteRule     ^-(.*)/(.*)?$                             /index.php?city=$1&ct=$2  
RewriteRule     ^-(.*)?$                                  /index.php?ct=$1  

Then on any items category when I click on any item I have a URL like:

www.sitio.com /-city / category / nombreitem

Note the “-” sign I have, I won´t this but I can´t, but in the worst case I will be ok with that.

BUT when I choose a city from the main cities selection and it filter all ads from that specific city, then the generated url when I enter an item is:

www.sitio.com /-city / city / category / nombreitem

So, I have repeated twice the city in the url and that’s what I do not want!

But… how to take it off?

thanks.

rashid,

First, there is a MAJOR problem with using the :kaioken: EVERYTHING :kaioken: atom, the (.*), because it is “greedy,” and because most do not allow “an escape” from the loop it generally causes. However, you have successfully ordered your mod_rewrite code to eliminate the greedy effect and, because the leading - prevents capturing unwanted links, you seem to have conquered the main problems.

Rather than use the leading -, I would have used RewriteCond statements to test whether the {REQUEST_FILENAME} exists as a file or directory.

Now, to your question: The problem with having city twice is in your link generating code, not in your mod_rewrite. Without seeing that code, there’s no way for us to help. Since it’s PHP code, you’d likely get a faster response if I move (please do NOT duplicate a post) this to the PHP board but it doesn’t sound like it would be difficult to spot the problem.

Regards,

DK