简体   繁体   中英

Shortening URL containing query strings

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 ?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM