Custom rewrite_rules – only pass numbers and not alphabetic characters

Instead of index.php/reco/?b=$1, try this: “$wp_rewrite->index?pagename=reco&b=” . $wp_rewrite->preg_index( 1 ) You should also append a $ to your reco/([^/]*)/? regex to ensure the rule only matches the entire path, and not just the beginning. Then flush your rules afterwards (just re-save your permalink settings in admin). Update: Try using the page_rewrite_rules filter instead, and use … Read more

Performance impact of rewriting WordPress URLs

From performance point of view what takes time is matching URL against generated (and stored persistently so it’s not rebuilt continuously) list of regular expressions. Since URLs are (most of the time) insignificantly short in text volume the amount of those regular expression rules has most impact on performance. Unless you generate unreasonably many rules. … Read more

Apache Fallback instead of add_rewrite_rule

This fixed my issue. function my_query_vars($vars) { $my_vars = array( ‘PARAMETERS’ ); return array_merge($my_vars, $vars); } add_filter(‘query_vars’, ‘my_query_vars’); function my_rewrite_rules($rules) { global $wp_rewrite; $my_page=”PAGESLUG”; $my_rule = array( ‘URL/?’ => ‘index.php?pagename=” . $my_page . “&school_type=$matches[1]’ ); return array_merge($my_rule, $rules); } add_filter(‘page_rewrite_rules’, ‘my_rewrite_rules’);

Rewrite slug of custom post type to include post-id

Try this : function change_post_type_link( $link, $post = 0 ){ if ( $post->post_type == ‘questions’ ){ return home_url( ‘questions/’. $post->post_name .”https://wordpress.stackexchange.com/”. $post->ID ); } else { return $link; } } add_action( ‘init’, ‘change_rewrites_init’ ); function change_rewrites_init(){ add_rewrite_rule( ‘questions/([a-z-]+)/([0-9]+)?$’, ‘index.php?post_type=questions&p=$matches[1]&postid=$matches[2]’, ‘top’ ); } Here post slug is attached after questions in the URL. For example questions/q-slug/45. … Read more

add_rewrite_rule on multisite doesn’t work

It seems the problem is not with add_rewrite_rule rather with the .htaccessfile for the multi site. One of the test addresses was http://example.com/foobar/def/whatever.php Here’s a part of the htaccess which causes the result (Line 2) RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] If I comment this line out it works … Read more

Simple page URL rewrite with add_rewrite_rule()

The second argument of add_rewrite_rule is not a path, it the query string you want WordPress executes. This should work for example.com/sub-folder/thepage/ (change page_id with ID of your page): add_rewrite_rule(‘thepage/’, ‘index.php?page_id=12’); or with page slug: add_rewrite_rule(‘thepage/’, ‘index.php?pagename=thepage’); As you have WordPress in a subdirectory and you want to rip out the directoy name, you have … Read more

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