• Sorry, this problem was discussed, and rezolved with the code:

    function add_my_var($public_query_vars) {
        $public_query_vars[] = 'myvar';
        return $public_query_vars;
    }
    
    add_filter('query_vars', 'add_my_var');
    
    function do_rewrite() {
        add_rewrite_rule('mypage/([^/]+)/?$', 'index.php?pagename=mypage&myvar=$matches[1]','top');
    }
    
    add_action('init', 'do_rewrite');

    Where should I add that code? What file should I use and what section?

    I have a plugin installed that sets the URL’s like this: wordress/pagename/?var=xt
    i want it to be like:
    wordpress/pagename/xt

    Where wordpress is the wordpress base (https://domain.com/wordpress/)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Where should I add that code? What file should I use and what section?

    You should add it into a plugin or into your theme’s functions.php file.

    Preferably you would put it in the plugin that it is affecting.

    Thread Starter bughy

    (@bughy)

    Done that, but it says

    Error 404 – Not Found

    I’m using WordPress 2.6.3
    help ??

    mrpaint

    (@mrpaint)

    I’m using version 2.7.1

    As I look in ./wp-includes/classes.php:145

    $rewrite = $wp_rewrite->wp_rewrite_rules();

    Look in ./wp-includes/rewrite.php:1598

    function wp_rewrite_rules() {
    		$this->rules = get_option('rewrite_rules');
    		if ( empty($this->rules) ) {
    			$this->matches = 'matches';
    			$this->rewrite_rules();
    			update_option('rewrite_rules', $this->rules);
    		}
    
    		return $this->rules;
    	}

    So, they only use the cached rules. If we want to use our rules, we should update the cache. For example, I update in my options page when $_GET[‘updated’] == ‘true’

    PS: I also call add_rewrite_rule in init in case other plugin update cache later ??

    Hope it helps

    How to update cache?

    better explained

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Where to insert add_rewrite_rule?’ is closed to new replies.