GSTAR
(Omzy83)
December 8, 2009, 12:42pm
1
I currently have the following rule:
'rules'=>array(
'view/<id:\d+>'=>'search/view',
),
This gives me URL like this: /mysite/view/14197.html
On the page I have some values output from the database, I want to include some of these values in my URL rewrite so I get URL like this:
/mysite/view/14197-2-bedroom-house-manchester.html
($id - $bedrooms - bedroom - $type - $location)
How can I do this?
GSTAR
(Omzy83)
December 8, 2009, 5:39pm
2
Can someone please help me with this? Thanks
Y11
(Y!!)
December 8, 2009, 7:37pm
3
'rules' => array(
'view/<id:\d+>-<bedrooms:\d+>-bedroom-<type:\w+>-<location:\w+>' => 'search/view',
),
You can also do:
'rules' => array(
'view/<id:\d+>-<seo:.+>' => 'search/view',
),
So with the last rule you can add any value, this would work:
/mysite/view/14197-test.html
Is that what you’re looking for?
GSTAR
(Omzy83)
December 8, 2009, 7:56pm
4
That looks good to me, I will test it out tomorrow. Thanks!
GSTAR
(Omzy83)
December 9, 2009, 10:00am
5
What I’m actually trying to do is make it generate the URLs in the format I posted above. The only field that is matched in the database is the ID field, the rest will just be there for SEO purposes.
EDIT: It’s OK - I think I’ve figured it out. Thanks
GSTAR
(Omzy83)
December 9, 2009, 10:28am
6
Just having a slight problem - when I’m matching against values that have spaces it doesn’t seem to work.
For example: <location:\w+> sometimes contains two words, and the rewrite seperates the two words with a + symbol.
What do I need to do to make this work?
EDIT: I noticed underscore works - is it possible to make it generate underscore rather than plus symbol?
GSTAR
(Omzy83)
December 9, 2009, 12:58pm
7
I managed to figure this out. I just did <location:> in the rule and ‘location’=>str_replace(" ", “_”, $model->location) in the view.
This works, but I’m not entirely convinced it’s the correct way of doing it.