When you write your own WordPress plugin you might need to add new rewrite rules to WordPress. Some people add Rewrite rules direct into htaccess file, but when you open it you can see that WP don’t store rules into this file. All WordPress rewrite rules are stored into the database.
Default WordPress htaccess file
1 2 3 4 5 6 7 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> |
For manipulation with rewrite you can use WP_Rewrite class. It’s functions all listed at the WP Codes, but i will show you how to use most important ones.
rewrite_rules() function
1 2 3 4 |
function getRewriteRules() { global $wp_rewrite; // Global WP_Rewrite class object return=$wp_rewrite->rewrite_rules(); } |
This function “getRewriteRules”, will return array with listed rewrite rules. Array will be something like …
1 2 3 4 5 6 7 8 9 |
Array ( // .... [author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?author_name=$1&feed=$2 [author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?author_name=$1&feed=$2 [author/([^/]+)/page/?([0-9]{1,})/?$] => index.php?author_name=$1&paged=$2 [author/([^/]+)/?$] => index.php?author_name=$1 // ... ) |
Popularity: 49% [?]