I’m not sure how to do this, it’s a general url rewriting question as well as a urlManager question.
I have a URL that is basically a user friendly search url, so for example:
What I need is this to redirect to:
I thought the following would work, but I just get a 404 error:
I’m not 100% sure how to get the ‘-in-’ out of the url and pull the other two words as GET variables. I managed the same thing before, converting:
And the above code for the property view page works perfectly. I thought I was using the same principles as the above rule to get the category and location from the search url but it’s just not working!
I also think there may be an issue with the ‘+’ symbol in the location string if I do get this working?
[font="arial, verdana, tahoma, sans-serif"][size="2"]<category:\d+> and <location:\d+> expects category and location to be decimal numbers. <category:\w+> and <location:\w+> should be used instead.[/size][/font]
Of course! Thanks!
Just one more issue, is there a regexp to ignore any + symbols in the url, for example i now have as my urlManager rule:
'<for:\w+>/<category:\w+>\-<in>\-<location:\w+>' => 'property/search',
Which works great, it converts:
However it’s not allowing me to put the + symbol in the url, and if there’s a space in the town name or category name, the url will contain the + symbol, eg:
And this throws a 404 not found error. Does anyone know best way around this?
It seems that + signs are replaced by spaces automatically before routing, so you need to check for spaces in the pattern.
A regexp-guru may come up with a better solution but this will do the job:
Thanks a lot for that, it’s absolutely perfect! I’ve never really got on with regexp, I think I need to take some time out to learn it a little better!