Reputation: 16495
These days, I am seeing more a more, URL like this: example.com/this_is_content_title
I am not sure how this is done, or possible even. I know most sites use something like example.com/108/some_text_here
with the 108
part being an identifier/id of the news but, how is it possible to append the title just after the domain name and how to fetch from database?
My guess it they are appending it using apache, but why can't we see the identifier and how do they search/find the content based on the text?
maybe:
$title = str_replace(array('_', '/'), '', $_SERVER['REQUEST_URI']);
$query = "SELECT * FROM article WHERE title = '$title'";
I am assuming that is how they retrieve the contents from database, even though it seems not efficient way to do it. Because, it would be much more speedy to search for an article based on id's instead of a whole sentences.
Anyway, if that is how they show the articles, how does one just append title into the URI?
Don't tell me it is something like this:
$row['title'] = 'I am title for some article';
echo "<a href='http://example.com/".str_replace(' ', '_', $row['title'])."'";
Upvotes: 0
Views: 83
Reputation: 656
I can't explain it very well but I was reading the Apache docs on URL rewriting and it is quite easy to do what I think they called a 'silent' redirect, so that without changing the URL client-side the server redirects all requests for example.com/this_is_content_title
to example.com/108/some_text_here
or for that matter example.com/?id=108
.
Aside from server configuration, I think WordPress does this with PHP when you enable pretty permalinks
, so the WordPress repos and codex might be a good place to look for more details.
Upvotes: 1
Reputation: 3686
You are right, that is how it is done, and the string is indentifier here. Also workaround here would be ENUM of all identifiers but lets not go too deep into it.
It seems not efficient way for you, I see your point, but hey this action is only ~0,01sec slower and gives you a lot of advance on SEO because you have clean url, so nothing too bad there...
Upvotes: 1
Reputation:
this is call seo url you can see some samples here http://davidwalsh.name/htaccess-url
Upvotes: 1