2

I'm using Codeigniter(PHP Framework) and I have URLs like http://www.mysite.com/age/21/gender/female/name/jamie/city/boston/userid/1234.

Is it possible to make the URL more SEO/user friendly? Like http://www.mysite.com/1234-Jamie-Boston and somehow still be able to pass the values found in the original URL strings like age =>21 and gender => female?

3
  • Have you tried GET parameters? or query string Commented Jul 5, 2011 at 5:17
  • I try not to use query strings as its against the design of the Codeigniter framework. I'm writing a search engine for a site and the URL is really long with lots of parameters in the segment based URLs http://www.mysite.com/searchterm/funny/since/2011/sortby/ratings/shorterthan/3/page/5 Commented Jul 5, 2011 at 5:30
  • My apologies i didn't see the codeigniter tag Commented Jul 5, 2011 at 5:36

2 Answers 2

3

I think you could - use mod_rewrite to rewrite your new url from http://www.mysite.com/1234-Jamie-Boston to http://www.mysite.com/user/1234. In your user controller load from the db the one with id 1234 and set all his other properties

Or without the mod_rewrite - you could modify your application/config/routes.php file with an entry like:

$route['(\d+)-.*'] = "users/display_user/$1";

This way your SEO friendly urls will point to class Users, method display_users and you will get the id as parameter

Sign up to request clarification or add additional context in comments.

1 Comment

+1 from me. I've used the routes.php approach, and left my .htaccess file alone. In that scenario I was able to treat all top-level sub directories differently from my "industries" pages - essentially, made it easy to write an abstract class for everything and a distinct class just for industries. btw - watch the order of your routes.
2

The way that PHP works is that if you send 15 parameters to a function which only requires two, then PHP can more or less "swallow" the other arguments (they're still accessible, but they are less than optional). In your case, I would create a Users controller, perhaps with a display function which only takes one parameter, the user ID. That way, you can have /users/display/1234/whatever/you/would/like/zodiac_sign/stop_sign/favorite_letter/favorite%20punctuation/... Need I go on?

You can get around the need for a controller/method as part of your URL by using the $routes config file... In this case, I don't think user/display would really hurt SEO. I would not use mod_rewrite to do that simply because the architecture is already there in CodeIgniter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.