I am asking about a feature in WordPress
add_filter( ‘option_rewrite_rules’, $array, $int, $int );
and how it can be used to rewrite the post URL
Here is an example that used this feature to rewrite the categories URLS to sub-domains so that the category URL became like this :
category-slug.xyz.com
instead of :
xyz.com/category-slug
The example :
public function change_rules_array_posts( $ruless, $post ) {
if ( is_array( $ruless ) ) {
echo $post->ID;
//replace all feed rules
$ruless["feed/(feed|rdf|rss|rss2|atom)/?$"] = "index.php?category_name=" . $this->subdomain->slug . "&feed=$matches[1]";
$ruless["(feed|rdf|rss|rss2|atom)/?$"] = "index.php?category_name=" . $this->subdomain->slug . "&feed=$matches[1]";
if ( 0 == $this->settings[ 'using_index' ] ) {
$rules2 = array();
$rules2["$"] = "index.php?category_name=" . $this->subdomain->slug . "&p=1";
$rules2["page/?([0-9]{1,})/?$"] = "index.php?category_name=" . $this->subdomain->slug . "&p=1&paged=$matches[1]";
$rules = $rules2 + $rules;
}
}
return $rules;
}
add_filter(‘option_rewrite_rules’, array( &$this, ‘change_rules_array’) );
The question is How can I use it for doing the same thing with posts URLS
New Updates :
i found a filter according to WordPress to change and rewrite the post URLS
https://codex.wordpress.org/Plugin_API/Filter_Reference/post_rewrite_rules
but I still don’t know how to use it
This link is trying to explain how to use but I don’t know what to write inside the function :
http://hookr.io/filters/post_rewrite_rules/#
Any idea
Read more here: rewriting wordpress post url " option_rewrite_rules "