The main reason is because static URL`s (the second URL is static) are indexed more faster than dynamic URL`s (like the first one), because from a static URL is easier to understand what the page is about both for search engines and your visitors. When using dynamic URL`s there is an another problem: search engines are reading only the beginning of the long URL`s, so if your addresses are different only at the end, than search engines will see the same URL for all of your pages and from this reason none will be indexed.
How this works ?
We will use Apache mod_rewrite. The mod_rewrite transforms back the second URL into the first URL, so the server will access the "ugly" address, but the visitors and the search engines will see the "clear" one. mod_rewrite simply rewrites the URL`s what meets specific conditions into addresses what are understood by the server.
Let`s rewrite it!
The code what rewrites the website address needs to be placed in your .htaccess file (if you don`t have it in your root folder, create it), the code is very short:
RewriteRule ^tutorials/(.*)/(.*)-([0-9]+)/?$ /tutorials.php?id=$3&title=$2&category=$1
Take it apart!
The first line: RewriteEngine on simply does what it says, it starts the rewrite engine.
Now let`s take apart the second line:
^ - this exponential sign means the start of the URL: http://www.mywebsite.com/
tutorials - this word is simply added to the website adress
/ - this character separates the directories
(.*) - this tells the server that here will be placed some data (any kind of characters) (e.g.: php)
- - this character will be simply added to the website adress
([0-9]) - this tells the server that here will be placed a digit (e.g: 1)
+ - the plus sign tells the server that here can be more digits (e.g.: 123)
? - this sign tell the server that the character in it`s front it`s not required (so the URL will work with and without the last "/")
$ - the dollar sign tells the server that here is the end of the rule
I know that it`s not easy, if you have any question please don`t hesitate, ASK ME! And I will try to answer as fast as I can. You can for example write me in a comment your URL and how you want to transform it and I will try to make it ;)
Post a Comment Blogger Facebook
Click to see the code!
To insert emoticon you must added at least one space before the code.