Home » , , , , , , » Mod rewrite tutorial. Creating seo frendly urls in php

Mod rewrite tutorial. Creating seo frendly urls in php

mod rewrite

Hello dear readers.
In this tutorial i will explain in deepth how to make your url's beautiful and better for seo.

Benefits of mod_rewrite:

1) they are beautiful
Lets take an example:
Non rewrited url:
http://facebook.com/profile.php?id=12324231
Rewrited url:
http://facebook.com/PhpTutorials
Cool isnt it ?
2) Security
mod_rewrite is build in security
You can use some kind of filters who allow only 0-9 or a-z etc.. by not allowing dangerous charachters

Lets move on

To make mod_rewrite work we must go to apache http.conf and add this line:
LoadModule rewrite_module modules/mod_rewrite.so Then restart apache.
Now at root open or create .htaccess if you havent it
Lets for example rewrite the profile.php url:
RewriteEngine On
RewriteBase /
RewriteRule ^profile/([a-zA-Z0-9-!./]+).html$ profile.php?id=$1

Thats it, you can now integrate this rule with php scripts and here it is a tutorial

2 תגובות:

  1. Wordpress have this function ,without making change to .htaccess

    ReplyDelete
    Replies
    1. Wordpress does that for you, it edits it

      Delete

Follow by Email