Wednesday, February 22, 2012

Directory Model URL Rewriting with htaccess and map content with php

Creating a dynamic content for web application, we need to consider the Search Engine Optimized web URL structure to main the quality of our web development says "SEO Friendly", Search Engines are clearly identified our web content if we have Directory Model URL structure in our websites. As a developer SEO Friendly URL is very important to any project. Let me explain How to create Directory Model URL Rewriting with htaccess and how to map your content with php.

.htaccess directory structure url rewriting



directory structure:

/index.php
/.htaccess
/include/home.php
/include/about_us.php
/include/contact_us.php



.htaccess

Options +FollowSymLinks
RewriteEngine On
# Level 1 Directory with and without Trailing Slash
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?topic=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?topic=$1

# Level 2 Directory with and without Trailing Slash
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?topic=$1&subtopic=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?topic=$1&subtopic=$2 


Download This Script    View Demo & Download Script

3 comments:

  1. The best URL Rewrite tutorial!

    ReplyDelete
  2. Notice: Undefined index: topic in C:\xampp\htdocs\directory-model-url\index.php on line 7

    ReplyDelete