Google YahooMyWeb Digg Technorati Delicious Äîáàâèòü íà ÑÌÈ2 Äîáàâèòü íà Habr Äîáàâèòü íà Moi Novosti

Pretty URLs - a guide to URL rewriting

Eklenme Tarihi: December 17, 2007 04:51:09 AM
Ekleyen:
Kategori: Webmaster Kaynakları: Programlama-Seo

Commonly, the method for passing data to the script is via the query string. The resulting links to your pages can therefore end up complicated and unfriendly. For example: http://yourdomain.com/articles/show.php?category=8&article=145&page=3

The concept of "pretty URLs" involves converting these complex dynamic URLs into easier to read, static URLs: http://yourdomain.com/articles/8/145-3.html

For the sake of clarity and to save unnecessary repetition, I will refer to the first format as "ugly" and the second as "pretty" for the rest of the article. These terms are commonly used with regards to this technique.



Why use pretty URLs?

Pretty URLs have been a common SEO technique for many years now but many of the early benefits are no longer applicable. The bad news is if you are hoping to massively boost your search engine rankings by using pretty URLs, you're about ten years too late. You would be much better off spending the time writing better content.

The good news is you can still benefit from it - keywords in the URL often help with SEO, and there are claims that a static extension such as .html is preferred over the dynamic (.php, .cgi and so on). However, the main reason I will always incorporate URL rewriting into my own projects is it makes the whole application look a lot neater and more professional.

Whatever your reasoning is, pretty URLs are so simple to setup - what have you got to lose?

Note: if your website is already launched, indexed in search engines and linked to from other websites, do not change the URL format unless you are certain you can preserve these inbound links with the appropriate 301 redirects.



How to use pretty URLs?

You have two options here. The first is fairly obvious and almost equally useless - that is, create your chosen file structure either manually every time you update your content, or more sensibly, automatically using server side scripting. As I'm sure you realize, if your pages update very frequently (for example, if you had an online users display), this method is not a viable option. Even without rapidly changing content, you can usually save yourself a lot of work by using URL rewriting.

URL rewriting is a very powerful process that allows your server to receive requests in a certain format, such as our new pretty URL and transparently convert it into our old ugly format in order to locate and retrieve the appropriate resource. I used the term transparently because anyone browsing your site will have no knowledge of this process going on - similarly, neither will any search engine bots.

The process of URL rewriting is carried out by a rewrite engine. The specifics of this are dependent on the server you are using. We will use Apache as an example here. The rewrite engine for Apache is contained within the mod_rewrite module. On a shared hosting account, this should already be enabled - if not, contact your host. If you run your own server, you may need to enable this module by uncommenting the relevant LoadModule command in your httpd.conf. There are plenty of resources readily available to help you with this, and as this is not an article on server administration, we will move on to the more interesting aspects.

Note: Rewriting can only change where the server looks for the requested resource. We cannot automatically change our links using a rewrite engine; you must manually change the output of your pages or scripts to generate the href link in the new pretty format.



mod_rewrite

You have probably already heard of mod_rewrite. The massive power of this module has led to the common misconception that it is "voodoo" or "black magic". Please do not be discouraged by these claims - it really is very easy to use and for most uses, there are probably only two directives you need to know. The full documentation is available from the Apache docs website - apart from the trivial On/Off command, we will only use RewriteRule.

If you are comfortable with a server side scripting language (such as PHP or Perl) but even after reading this tutorial do not understand mod_rewrite, there is an easy way out. I will come back to this at the end.

Let's briefly go over the syntax. We need some way of telling Apache we want to use URL rewriting. As you may already know, we can either do this directly in the Apache configuration file, the httpd.conf or much easier, a per-directory context using .htaccess files. A .htaccess file is merely a method of passing instructions to Apache. These are plain text files, named ".htaccess" (without quotes) and when placed in a directory, the instructions are interpreted by the server whenever a resource (file, image, web page, etc.) is requested from within the directory. You may already be using .htaccess files - if so, simply add in your new rewrite code at the end.

 

more....

Oylama Yapabilmek icin giris yapmalisiniz. Ortalama: ( oy)

Yapilan Yorumlar
Gorus Yazabilmek icin giris yapin.

Yeni Makaleler

Understanding Goals and Conversion Optimization
If you use Google Analytics, you’re probably familiar with the terms Goals, and Conversions.
200 Adet pr1 - pr 4 dizin
200 Adet pr1 - pr 4 dizin
550 Adet Yüksek Prli Dizin
550 adet pr1 ve pr8 arası webdizini.
BaÅŸka Bir Dizin Listesi
Sitelerinizi ekleyebileceÄŸiz baÅŸka bir dizin siteleri listesi
pr9-pr5 web dizini adresleri listesi
pr9-pr5 pageranka sahip dizinlerin yer aldığı adres listesi

 Istatistikler

  • Aktif: 182
  • Onay Bekleyen: 0
  • Bugun Eklenen: 0
  • Makaleler: 39
  • Kategoriler: 18
  • Alt Kategoriler: 55

 Gunun Makalesi

Concealed Strategies Internet Marketing

"What am I doing wrong?" Sometimes you wonder how come competing websites get so many daily visitors

 Text Reklam

Bilgi Ve Eglence İksiri

 Yeni Eklenenler

 Adsense

 Alexa Stats