Here is what you need to do:
RewriteEngine On RewriteBase / RewriteRule ^([a-z0-9_\-]+)/?$ index.php?main=$1 [NC,L] RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/?$ index.php?main=$1&sub=$2 [NC,L]
This will allow you to have pages such as:
http://www.domain.com/mainpage/ or http://www.domain.com/mainpage or http://www.domain.com/mainpage/subpage/ or http://www.domain.com/mainpage/subpage
/? means slash is optional
[NC] This makes the case insensitive - the differences between "AZ" and "az" are ignored in both the extended TestString and CondPattern. This flag is only effective for comparison between TestString and CondPattern. It does not affect file system checks and subqueries.
[L] The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, further rules will not be processed.
All information about flags and rules: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Book of zeus
source share