Url manipulation with mod_rewrite and php-catcher for beginners

Url manipulation is one of the hottest areas on the new generation web (2.0). It provides more security and flexibility. It is user and search-engine friendly. The most popular combination is Apache-webserver + mod_rewrite + server-side catcher(mostly a php-file). In this tutorial we use very short examples to make it easy for newbies.

Why url manipulation & mod_rewrite?

  1. more security: hide file location
  2. shorter urls without file extensions like .html
  3. easy to remember / recommend urls
  4. search engine friendly
  5. easy to manage structure

old url:

new url:

Can you tell a friend the first url on the phone or send with a sms?


  1. .htaccess
  2. catch.php
  3. page1.html
  4. page2.html


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ catch.php?p=$1 [L,QSA]

"RewriteCond %{REQUEST_FILENAME} !-f" means if requested path is not an existed file
"RewriteCond %{REQUEST_FILENAME} !-d" means if requested path is not a real directory



$p = $_GET[p]; // p means page or path

// use white-lists against possible code-injections

$my_pages["my/first/url"]	= "page1.html";
$my_pages["second-url"] 	= "page2.html";

if( $my_pages[$p] && file_exists( $my_pages[ $p ] ) ){

 include( $my_pages[ $p ] );

} else {

	echo "Page not found: $p";



Welcome to page 1!


This is page 2.

Now test it with calling urls on your website:

Links for detailed information & guides:

Download url_manipulation_mod_rewrite.zip1.06 KB


SEF Ulrs

Making the Urls Search Engine Friendly by keyword rich in the url.It is liked by search engines and it is easy to remember by humans also.Your url will rank high if it is seo friendly.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.