You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
I’m going to transform URL from sitename.com/single.php in a single article page? url = article-name to sitename.com/article-name. To do this, we need to change the pattern of the URL and the Orignal URL, and everything is the same. That’s rules that start with RewriteRule and the flags.
In URL Pattern, we will search for various phrases by using \w and in conjunction with +. Here is the full URL Pattern for Single Article Clean URL Pages – ^([-\w]+)$
Next Original URL, will we use the original single.php url? url= article-name. We will retrieve the URL patter with $1 instead of the article-name. And the final Original URL will look like single.php? url=$1
Next its same NC flags for case-insensitive and L for the end of the rule. The complete rule for Category URLs.
RewriteRule ^([-\w]+)$ single.php?url=$1 [NC,L]
Category URLs are also the same as Single-Article URLs, except that using additional category slug in the category here in the URL category. Starting and ending the URL is the same.
Here is the structure of the category URL before and after, that is from sitename.com/index.php?category=category-name to sitename.com/category/category-name
URL pattern will be comparable to Single Article Page URL pattern, an additional category slug with word pattern will be introduced. Our complete URL model for category URLs is ^category/([-\w]+)/(\d+)$
The original URL is the same as the past rule, which is a single article URL. The pattern is obtained as $1. The final original category pages URL is category.php? Url=$1
Next, it’s same flags NC for case-insensitive and L for the end of the rule. The complete rule for URLs in categories.
RewriteRule ^category/([-\w]+)/$ category.php?url=$1 [NC,L]
This looks like the category URL with pagination before and after.
From sitename.com/index.php?category=category-name&page=2
To sitename.com/category/category-name/2
Add additional pattern group to the category rewrite rule URL pattern and also to the original URL to make pagination URLs as a clean URL.
This pattern group is total numbers, so use \d with + for various numbers. And the final pattern of the URL will be (\d+). The complete paginated URL pattern is ^category/([-\w]+)/(\d+)$
Next is the original URL, here we should retrieve the second pattern that will be represented as $2 and the final original URL will look like category.php? url=$1&page=$2
Next its same NC flags for case-insensitive and L for the end of the rule. The complete rule for the Pagination URL category is:
RewriteRule ^category/([-\w]+)/(\d+)$ category.php?url=$1&page=$2 [NC,L]
Credit: Arpatech - Simple Steps for Creating Friendly URL’s with PHP & HTACCESS