Simple serach friendly url rewrite rules

Scenario:

Example:
http://somesite.com/mydir/a
http://somesite.com/mydir/b
http://somesite.com/mydir/c
etc...

To be rewritten as:
http://somesite.com/mydir/view.php?p=a
http://somesite.com/mydir/view.php?p=b
http://somesite.com/mydir/view.php?p=c
etc...

Except:
http://somesite.com/mydir rewrite--> /mydir/home.html
http://somesite.com/mydir/home rewrite-> /mydir/home.html
http://somesite.com/mydir/about rewrite-> /mydir/about.html

Solution:

These rules should go in an .htaccess file in the "mydir" directory:

DirectoryIndex home.html
Options +FollowSymLinks
RewriteEngine on
RewriteBase /mydir/
RewriteCond %{REQUEST_URI} ^/mydir/(home|about)$
RewriteRule ^.*$ %1.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ view.php?p=$1 [L]

Related links

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Extending above url re-write for a second variable

DirectoryIndex home.html
Options +FollowSymLinks
RewriteEngine on
RewriteBase /mydir/
RewriteCond %{REQUEST_URI} ^/mydir/(home|about)$
RewriteRule ^.*$ %1.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ view.php?p=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ view.php?p=$1&q=$2 [L]

Note:
"[^/]+" matches one or more characters not equal to a slash.
"?" matches 0 or more.

Comment