RewriteRule accepts numbers but not letters in tag

Leave .htaccess alone. You can use WordPress rewrite API for this. add_action( ‘init’, function(){ return add_rewrite_rule( ‘subdir/([^/]+)/?$’, // ([^/]+) takes alphanumeric, while ([0-9]+) accepts digits ‘index.php?pagename=subdir&website=$matches[1]’, ‘top’ ); }); add_filter(‘query_vars’, function($v){ return array_merge(array(‘website’),$v); }); First make sure subdir is a valid page slug, in this example. After you save that code to your child theme’s … Read more

How to catch Rewrite rules then display a specific post?

It appear, like @milo also said, that the correct way to doing this is by using the “parse_request” action that stand before the “pre_get_posts” action (see https://codex.wordpress.org/Plugin_API/Action_Reference). The complete solution I came with : add_action(‘init’, function () { $refs_slug = getCustomRefTermsSlug(); // this will return an array of all the terms slug existing in the … Read more

Static variable and add_rewrite_rule?

You can’t add arbitrary query variables to the rewrite rules, there’s a whitelist of allowed variables. To add a query variable, use query_vars filter, e.g. this filter adds my-api as a valid query variable: function wpd_query_vars( $query_vars ){ $query_vars[] = ‘my-api’; return $query_vars; } add_filter( ‘query_vars’, ‘wpd_query_vars’ ); But that just gets you the query … Read more

Url Rewriting a dynamic wordpress page

thanks for you reply, So after much digging, it’s working : function myplugin_rewrite_tag_rule() { add_rewrite_tag( ‘%symbol%’, ‘([a-zA-Z0-9_]+)’ ); add_rewrite_rule( ‘^crypto-monnaies/([a-zA-Z0-9_]+)/?$’, ‘index.php? pagename=showcoin&symbol=$matches[1]’,’top’ ); } add_action(‘init’, ‘myplugin_rewrite_tag_rule’); function add_query_vars( $query_vars ) { $query_vars[] = ‘symbol’; return $query_vars; } add_filter( ‘query_vars’, ‘add_query_vars’ ); Please note that if you dynamic page is a second level page, you have … Read more

WordPress custom post type permalink: website.com/post-name/post-id

product/([0-9]+)?$ translates to product/ followed by any number or nothing (and nothing more, not even a trailing slash). This doesn’t sound like the thing you want to achieve. Instead, try the following function wpse33551_rewrites_init(){ add_rewrite_rule( ‘^([^/]+)/([0-9]+)/?$’, ‘index.php?post_type=artikelen&p=$matches[2]’, ‘top’ ); } which translates to: ^ start of the string (ie, there is nothing else in front) … Read more

add_rewrite_rules for type of post

the URL index.php?pagename=to-kill-a-mockingbird&post_type=book&book_type=fiction works only for simple post or page. when you have a custom post type, the URL is index.php?book=to-kill-a-mockingbird&book_type=fiction. then try this code : add_rewrite_rule( ‘^books/fiction/([^/]*)/?$’ , ‘index.php?book=$matches[1]&book_type=fiction’ , ‘top’ );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)