What method can you recommended for creating search engine-friendly URLs? When coding in PHP that is. Ideally I would like something like:
http://www.example.com/article/523544
So it doesn't display the file it's opening (eg article.php)
What method can you recommended for creating search engine-friendly URLs? When coding in PHP that is. Ideally I would like something like:
http://www.example.com/article/523544
So it doesn't display the file it's opening (eg article.php)
Some basic tips from
may help you.
Some topics in SO:
Edit:
You need to place a .htaccess
file in your document root that includes the following rules:
RewriteEngine on
RewriteRule ^article/([0-9]+)?$ article.php?id=$1 [L]
Make sure mod_rewrite
enabled in Apache and you are allowed to use it.
If you read some questions in SO in this topic it will help you understand how mod_rewrite works.
To make your urls more search engine friendly you may want to use 'slugs' so you need to sanitize your article titles like in this url.
It is quite necessary to generate a SEO friendly URL's so that most of the Search engines can easily index it.And the most interesting part with it that URL can easily correlate to the Page Content and the User can generate a Pretty URL as per the keywords he want to rank the page on different Search Engines(e.g. google.com,google.co.in,bing.com)
The best example to have Pretty Links is on Wordpress.It actually stores the Dynamic Page URL's in the Database itself.And when the Pretty Ur is being called,internally the htaccess is called and it redirects to the original dynamic page in the system.
Ideally your URL needs to contain something about the topic of the URL. You gave the example of http://www.example.com/article/523544, where this is better than using standard query strings, it's still not ideal, as all that any search engine can see from it is that it's an article.
It's important to remember that the segment (a segment is the string between each slash) closest to the domain is the most important: http://www.example.com/most-important/next-important/less-important/
I personally always try to use the following URL structure, and keep my page/article titles unique: http://www.example.com/this-wonderful-article Notice the use of dashes and not underscores, this is generally known as the preferred method. Using this method I usually generate and save the article's slug ('this-wonderful-article') in the database, and then search for that instead of an ID.
Appreciated that sometimes it's very difficult to just use slug, especially with a larger website. You may have multiple articles with the same title, or the website may have user-submitted content over which you have no control. If this is the case, you can use the ID without any worries, but just be sure to include the title of the article in the URL. Eg: http://www.example.com/this-wonderful-article/29587
If you're looking for a method of using these URLs then I'd suggest looking at some mod_rewrite tutorials. Personally I use a framework that does the majority of the legwork for me such as CodeIgniter (http://www.codeigniter.com), or you could use something like the Zend Framework or CakePHP. If you're only doing articles then it might be worth looking into a sturdy CMS like WordPress, although this depends largely on your requirements.