Jonathon Posted January 10, 2013 Share Posted January 10, 2013 Hi Just wondered about this. Obviously you can view an inidividual record in Yii using the actionView() method. So for an example www.example.com/item/1 Would return that record. For SEO purposes it would be nice to load in the url www.example.com/item/1/items-name A couple of things for this. 1) Should I store a slug hyphenating the individual items name? Secondly is it just a case of using something like this in your routes '<controller:\w+>/<id:\d+>/<title:\^[a-zA-Z-]+>'=>'<controller>/view', I'm not sure if that is a Regex problem or not. I did check it out in a regex tester and it seems to work, but I get "The system is unable to find the requested action "1". when i try to load the page with a title. On the other hand '<controller:\w+>/<id:\d+>/<title:\w+>'=>'<controller>/view', allows me to find www.example.com/item/1/itemsname Which is half way there. I'm just not 100% sure what my problem is currently. I should also mention that the title "items-name" isn't important to me within a query. I'd be happy to just use the id to find a record. The title was purely for SEO/aesthetics. Thanks Jonathon Link to comment Share on other sites More sharing options...
Jonathon Posted January 12, 2013 Author Share Posted January 12, 2013 So, I used this rule in my config 'item/<id:\d+>/<title>' => 'item/view', Which works. The title placeholder accepts any characters. I am purely using this rule for user readability. Is that approach ok? I would assume so purely because the actionView() only accepts the $id. However if somebody could confirm this for me that would be great. I'm still a little unsure why when i try <title:\^[a-zA-Z-]+> It fails 1 Link to comment Share on other sites More sharing options...
Edward Posted January 13, 2013 Share Posted January 13, 2013 You have some of the same controller names as me most probably we are working on similar sites. I am leaving routes out to do last after main site functionality is completed. Sorry i could be of no help right now. Link to comment Share on other sites More sharing options...
Larry Posted January 18, 2013 Share Posted January 18, 2013 Jonathon, have you figured this out yet or are you still having difficulties with it? Link to comment Share on other sites More sharing options...
Jonathon Posted January 18, 2013 Author Share Posted January 18, 2013 Hey Larry, I just left it as 'item/<id:\d+>/<title>' => 'item/view', Which currently was ok, as I was just experimenting. However, I wasn't sure why 'item/<id:\d+>/<title:\^[a-zA-Z-]+>' => 'item/view', wasn't working. If you could let me know if there are any obvious errors with this that would be great as i'd prefer to use a regex to monitor what's in the url. That being said, i'll refer back to my last comment. As i'm purely using the title for decoration purposes, do I even need the regex as nothing in the url is using within the controller? Thanks for getting back to me 1 Link to comment Share on other sites More sharing options...
Larry Posted January 18, 2013 Share Posted January 18, 2013 If it's just for decoration and SEO purposes, and the script doesn't actually need that value (which totally makes sense to use that approach, by the way), then, no, you don't need the regular expressions. Link to comment Share on other sites More sharing options...
Jonathon Posted January 18, 2013 Author Share Posted January 18, 2013 Thanks for your help Larry. Yeah, I just wanted it to be friendlier for SEO and a bit more readable. Pleased to know I was right. Link to comment Share on other sites More sharing options...
Edward Posted March 18, 2014 Share Posted March 18, 2014 Hi Just wondered about this. Obviously you can view an inidividual record in Yii using the actionView() method. So for an example www.example.com/item/1Would return that record. For SEO purposes it would be nice to load in the url www.example.com/item/1/items-nameA couple of things for this. 1) Should I store a slug hyphenating the individual items name? Secondly is it just a case of using something like this in your routes '<controller:\w+>/<id:\d+>/<title:\^[a-zA-Z-]+>'=>'<controller>/view', I'm not sure if that is a Regex problem or not. I did check it out in a regex tester and it seems to work, but I get "The system is unable to find the requested action "1". when i try to load the page with a title. On the other hand '<controller:\w+>/<id:\d+>/<title:\w+>'=>'<controller>/view', allows me to find www.example.com/item/1/itemsnameWhich is half way there. I'm just not 100% sure what my problem is currently. I should also mention that the title "items-name" isn't important to me within a query. I'd be happy to just use the id to find a record. The title was purely for SEO/aesthetics. Thanks Jonathon I wonder how this works for Google analyzing your website. What happens when Google analyzes item/1/gun44 item/2/gun44 item/2-gun 44 instead of item/gun44-1 item/gun44-2 item/gun44-3 I used the 2nd method but the problem is you have to show list all the routes for other item controller actions in the config main.php so they can work. But if you done users you wouldn't want to go user/1 because you would be giving away there ID. And to solve the problem of listing extra routes in the main config file to have other user controller actions run. You could just do this user/member/edward instead of user/edward What eBay and their rival eBid did: http://www.ebay.com/itm/Star-Wars-Vintage-Collection-2010-DACK-RALTER-REBEL-PILOT-VC07-MOC/261422612497 (Looks like you may be onto something Jonathon) http://us.ebid.net/for-sale/star-wars-vintage-collection-79-darth-sidious-124699732.htm Link to comment Share on other sites More sharing options...
Recommended Posts