Rewriting in wordpress url

From this other answer on the WP SE add_action(‘generate_rewrite_rules’, ‘roots_add_rewrites’); function roots_add_rewrites($content) { $theme_name = next(explode(‘/themes/’, get_stylesheet_directory())); global $wp_rewrite; $roots_new_non_wp_rules = array( ‘css/(.*)’ => ‘wp-content/themes/’. $theme_name . ‘/css/$1’, ‘js/(.*)’ => ‘wp-content/themes/’. $theme_name . ‘/js/$1’, ‘img/(.*)’ => ‘wp-content/themes/’. $theme_name . ‘/img/$1’, ); $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules; } TheDeadMedic provided a much better version of this function: function … Read more

Add URL Rewrite Rule To WordPress

First you need to register your expected variables. Something similar to: function my_rewrite() { add_rewrite_tag(‘%ct_city%’, ‘([^&]+)’); add_rewrite_tag(‘%country%’, ‘([^&]+)’); } add_action(‘init’, ‘my_rewrite’, 10, 0); Then you need to create the rule which will redirect to your abm page. Note that you will need to discover your abm‘s ID, since you will need to pass it in … Read more

Rewrite rules for short URL

There are two types of rewrite rules you can generate via the API and add_rewrite_rule: internal rules and external rules. External rules get inserted into your .htaccess file, and must be in a format that can be parsed by Apache’s mod_rewrite. Internal rules get added to the WordPress internal rewrite rule array and must be … Read more

rewriterule not working

Terminology I think you have some terminology a little mixed up: A URL “rewrite” alters the endpoint of a HTTP request. If http://example.com/param/exam1 really serves content from http://example.com/examples/exam1?get=param, then the former is being rewritten to the latter (though not necessarily visible to the end-user). In the world of URL-rewriting, a “redirect” is a rewrite that … Read more

Add custom query vars to pretty permalinks

Use add_rewrite_rule to capture the url and convert to params internally. http://example.com/page{p}/t/{t} to http://example.com/?p={p}&t={t} Add to your function.php or in a plugin. <?php if ( ! class_exists( ‘SimpleRewrite’ ) ): class SimpleRewrite { const ENDPOINT_QUERY_NAME = ‘page’; const ENDPOINT_QUERY_PARAM = ‘__rewrite_page’; // WordPress hooks public function init() { add_filter( ‘query_vars’, array ( $this, ‘add_query_vars’ ), … Read more

Adding Rewrite URL for Base + Children Separately

Change your rewrite rules and the order to the following: add_rewrite_rule(‘my-url/([^/]*)/?$’, ‘index.php?my-var=$matches[1]’, ‘top’); add_rewrite_rule(‘my-url/?$’, ‘index.php?my-var=main’, ‘top’); Why the order? If the order would be the other way around, the first rule will always apply, so the ruleset would never reach your main page Why the changed syntax? To allow an additional query string to be … Read more

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