WordPress url rewrite has nothing to do with .htaccess file. WordPress url rewrite is done in wp() in wp-blog-header.php. wp() eventually calls parse_request in class WP, where a set of rewrite rules are matched against the request url, if matched, the request url is changed and redirection occurs.
The format of a rewrite rule is pattern=>real url. The real url corresponding to the first pattern that is matched against the request url successfully will be used to replace the original request url as the query. If none is matched and the request url is not an existing file, 404 not found will be produced. For example, if you type http://myprogrammingnotes.com/register in the address bar of the browser, the pattern of a rewrite rule: (.?.+?)(/[0-9]+)?/?$ will match the request uri: register successfully, the request url will be rewrite to pagename=register&page=. If the request url is http://myprogrammingnotes.com/register/12/, the rewritten uri is pagename=register&page=12. So any string after the domain part of the url will be mapped to page name even though the page might now exist. The complete rewrite rules are as follow.
category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?category_name=$matches[1]&feed=$matches[2]
category/(.+?)/(feed|rdf|rss|rss2|atom)/?$=>index.php?category_name=$matches[1]&feed=$matches[2]
category/(.+?)/page/?([0-9]{1,})/?$=>index.php?category_name=$matches[1]&paged=$matches[2]
category/(.+?)/?$=>index.php?category_name=$matches[1]
tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?tag=$matches[1]&feed=$matches[2]
tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?tag=$matches[1]&feed=$matches[2]
tag/([^/]+)/page/?([0-9]{1,})/?$=>index.php?tag=$matches[1]&paged=$matches[2]
tag/([^/]+)/?$=>index.php?tag=$matches[1]
type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?post_format=$matches[1]&feed=$matches[2]
type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?post_format=$matches[1]&feed=$matches[2]
type/([^/]+)/page/?([0-9]{1,})/?$=>index.php?post_format=$matches[1]&paged=$matches[2]
type/([^/]+)/?$=>index.php?post_format=$matches[1]
.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$=>index.php?feed=old
.*wp-app\.php(/.*)?$=>index.php?error=403
.*wp-register.php$=>index.php?register=true
feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?&feed=$matches[1]
(feed|rdf|rss|rss2|atom)/?$=>index.php?&feed=$matches[1]
page/?([0-9]{1,})/?$=>index.php?&paged=$matches[1]
comments/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?&feed=$matches[1]&withcomments=1
comments/(feed|rdf|rss|rss2|atom)/?$=>index.php?&feed=$matches[1]&withcomments=1
search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?s=$matches[1]&feed=$matches[2]
search/(.+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?s=$matches[1]&feed=$matches[2]
search/(.+)/page/?([0-9]{1,})/?$=>index.php?s=$matches[1]&paged=$matches[2]
search/(.+)/?$=>index.php?s=$matches[1]
author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?author_name=$matches[1]&feed=$matches[2]
author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?author_name=$matches[1]&feed=$matches[2]
author/([^/]+)/page/?([0-9]{1,})/?$=>index.php?author_name=$matches[1]&paged=$matches[2]
author/([^/]+)/?$=>index.php?author_name=$matches[1]
([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]
([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]
([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]
([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]
([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]
([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]
([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$=>index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]
([0-9]{4})/([0-9]{1,2})/?$=>index.php?year=$matches[1]&monthnum=$matches[2]
([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?year=$matches[1]&feed=$matches[2]
([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$=>index.php?year=$matches[1]&feed=$matches[2]
([0-9]{4})/page/?([0-9]{1,})/?$=>index.php?year=$matches[1]&paged=$matches[2]
([0-9]{4})/?$=>index.php?year=$matches[1]
.?.+?/attachment/([^/]+)/?$=>index.php?attachment=$matches[1]
.?.+?/attachment/([^/]+)/trackback/?$=>index.php?attachment=$matches[1]&tb=1
.?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?attachment=$matches[1]&feed=$matches[2]
.?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?attachment=$matches[1]&feed=$matches[2]
.?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$=>index.php?attachment=$matches[1]&cpage=$matches[2]
(.?.+?)/trackback/?$=>index.php?pagename=$matches[1]&tb=1
(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?pagename=$matches[1]&feed=$matches[2]
(.?.+?)/(feed|rdf|rss|rss2|atom)/?$=>index.php?pagename=$matches[1]&feed=$matches[2]
(.?.+?)/page/?([0-9]{1,})/?$=>index.php?pagename=$matches[1]&paged=$matches[2]
(.?.+?)/comment-page-([0-9]{1,})/?$=>index.php?pagename=$matches[1]&cpage=$matches[2]
(.?.+?)(/[0-9]+)?/?$=>index.php?pagename=$matches[1]&page=$matches[2]
[^/]+.html/attachment/([^/]+)/?$=>index.php?attachment=$matches[1]
[^/]+.html/attachment/([^/]+)/trackback/?$=>index.php?attachment=$matches[1]&tb=1
[^/]+.html/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?attachment=$matches[1]&feed=$matches[2]
[^/]+.html/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?attachment=$matches[1]&feed=$matches[2]
[^/]+.html/attachment/([^/]+)/comment-page-([0-9]{1,})/?$=>index.php?attachment=$matches[1]&cpage=$matches[2]
([^/]+).html/trackback/?$=>index.php?name=$matches[1]&tb=1
([^/]+).html/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?name=$matches[1]&feed=$matches[2]
([^/]+).html/(feed|rdf|rss|rss2|atom)/?$=>index.php?name=$matches[1]&feed=$matches[2]
([^/]+).html/page/?([0-9]{1,})/?$=>index.php?name=$matches[1]&paged=$matches[2]
([^/]+).html/comment-page-([0-9]{1,})/?$=>index.php?name=$matches[1]&cpage=$matches[2]
([^/]+).html(/[0-9]+)?/?$=>index.php?name=$matches[1]&page=$matches[2]
[^/]+.html/([^/]+)/?$=>index.php?attachment=$matches[1]
[^/]+.html/([^/]+)/trackback/?$=>index.php?attachment=$matches[1]&tb=1
[^/]+.html/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$=>index.php?attachment=$matches[1]&feed=$matches[2]
[^/]+.html/([^/]+)/(feed|rdf|rss|rss2|atom)/?$=>index.php?attachment=$matches[1]&feed=$matches[2]
[^/]+.html/([^/]+)/comment-page-([0-9]{1,})/?$=>index.php?attachment=$matches[1]&cpage=$matches[2]
The rewrite rules are stored as the rewrite_rules option in database table wp_options.
How to add rewrite rules in WordPress?
Unfortunately, there is no way for you to fully customize rewrite rules in the administration panel except in the permanent links settings page where you can alter the links for posts, categories, and tags. You can add new rewrite rules in a plugin by calling the api function add_rewrite_rule. This way you can for example add custom rewrite rules for new post types.