[RESOLVED] Some doubts regarding URL rewrite
Hi :wave:
I have been going through certain tutorial for some hours now, to know more about URL rewriting.
But I have a doubt:
If my site is kind of displaying articles, a sample link could be:
Code:
http://www.mysite.com/my-article-name-123
Where, 123 is the article id and the rest of the string is the article title. If a user types this address on his/her browser, we could easily match the last article id using regular expression(in Rewrite rules).
So the rewrited URL might look something like this:
Code:
http://www.mysite.com/showarticle.php?id=123
But how would we give this link. I mean, this link should be coming from somewhere. That is how this link will be created ?
If I'm not using the URL rewriting, I would use the address:
Code:
http://www.mysite.com/showarticle.php?id=123
for hyperlinks displayed in my site.
Eg:
Code:
<html>
<body>
<a href="http://www.mysite.com/showarticle.php?id=123">My First Article </a>
</body>
</html>
But in the case of URLs with article_names, how will I do it ? :confused:
Thanks in advance :wave:
Re: Some doubts regarding URL rewrite
Write all URLs on your pages in their "pretty" format; if you don't publicize the query string-based URLs, no one has to know about them.
Re: Some doubts regarding URL rewrite
Thanks :wave:
What all things should I have to make it pretty ? One is, to replace the space character with a "-" character. What else should I have to do to that article title, inorder to make it neat.
If you were in place of me, what all things would you do. (let me know the steps) :)
Re: Some doubts regarding URL rewrite
Re: Some doubts regarding URL rewrite
Make them short.
They should be created by humans, not simply encoded by a script.
Too many blogging platforms create long URIs out of titles. Instead, pick a key word and use that.
For example:
http://example.org/NiceURIs
Not
http://example.org/How_to_use_mod_rewrite_to_get_rid_of_query_strings
There should be one 'canonical' URI (the preferred version) as well as multiple others that can be used to access the same resource. If the user accesses the page through a 'non-canonical' URI, use a 301 redirect to send them to the proper one.
Also, I like using title case or sentence case, but make the URI parser case-insensitive, so that the user doesn't have to remember which letters to capitalise. If they use the wrong case, redirect to the correctly-cased URI.
Look at Wikipedia (the software they use, not a Wiki article) for an example of this done well.
Re: Some doubts regarding URL rewrite
Thanks :wave:
So, the URI should be created once, should be short and has to be stored in the database. Isn't it ? Each time, when I display links of that articles, instead of creating the URI on the fly again, it should display the one that we have created.
Got it now. :thumb: