Welcome Guest, Not a member yet? Register   Sign In
URL Rewriting: Name instead of ID
#13

[eluser]perfectsam[/eluser]
Thank you guys for the various inputs.

First of all, the functions rawurlencode() and CI's url_title() are not ideal for me, since names in the db have a lot of special characters in it (äöüéàèåñ) and those functions would simply replace them with ''. müller -> mller.
I've already found a suitable function which seems to work with all names I quickly tested: http://www.php.net/manual/en/function.pr....php#96586

So basically, I want to achieve 2 things with the new URLs:
- SEO
- user-friendly URLS, so users can type in the name instead of the ID which they almost never know, hence also the removal of '/show' (<-- haven't tried that one yet)

That means your last solution (www.example.com/authors/123/john_doe), mddd, is not very suitable for me since the users don't know the ID.

[quote author="mddd" date="1279714564"]1. Why use a redirect? Why not have the page stay on its own url? It would be perfectly ok to do so. That way, name and id would be equal. Not having the name simply a redirect to the id. Think of bookmarking for instance. Wouldn't it be much nicer for the user to bookmark 'authors/john_doe' than 'authors/show/123' ? FAR more useful to keep the name in there! And better for SEO too, I would think.[/quote]
I don't quite understand this. How would I implement this? As for bookmarking, the user bookmarks 'authors/show/john_doe' with the method I use now, except when he browses the author list and right-clicks on an author and bookmarks it. The link would then be 'authors/show/123' but the bookmark title would still be the author name, so it doesn't really make a difference.

[quote author="KingSkippus" date="1279732107"]Not to mention, what happens if you have two John Does in your database? Are you going to resort to .../john_doe and .../john_doe2? That’s not user-friendly at all.[/quote]
Yes, that's a big problem. At the moment, all the names are different, but of course that can change and I agree, a john-doe2 would not be very ideal but I don't see how I could do it differently with the method I use now.
Edit: I think a slightly better way would be: The page has an add author form. I could change the add function so that it is not possible to add an author with a name (first+lastname) that already exists and tell the admin who adds the authors that when this should happen, he should add it just like this:
First Name: "John"
Last Name: "Doe (2)"
or something like that. This way, they would also be distinguishable in the author list. and the URL would look like john_doe_2


So my code looks like this now, including the url function:

Code:
if (is_numeric($author_id))
    {
        $author = $this->author_db->getByID($author_id);

        redirect('authors/show/'.make_url($author->getName()));
    }
    else
    {
        $author = $this->author_db->getByName($author_id);
    }

Now, I have to change the getByName function since it only returns the author if it's like this: "John Doe" but $author_id contains "john_doe" now and the function doesn't return anything. Wink


Messages In This Thread
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 04:50 AM
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 05:03 AM
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 05:05 AM
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 05:05 AM
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 07:20 AM
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 06:41 PM
URL Rewriting: Name instead of ID - by El Forum - 07-20-2010, 07:25 PM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 01:16 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 05:57 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 06:00 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 06:08 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 06:11 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 07:54 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 07:58 AM
URL Rewriting: Name instead of ID - by El Forum - 07-21-2010, 12:25 PM
URL Rewriting: Name instead of ID - by El Forum - 07-26-2010, 10:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB