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 PHP: 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.
Try using explode('/', $_SERVER['QUERY_STRING']), then you get an array with all parameters so you can buid-up all links you want.