• Hi there !

    I’ve some troubles with custom url rewriting … Let me explain πŸ™‚

    I’ve this code on my functions.php file :

    // Ajout rewrite rules
    function flush_rewrites() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }
    
    function add_rewrites($rules) {
    global $wp_rewrite;
    $ftc_new_non_wp_rules = array(
    	'templates-wordpress/page/(\d+)' => 'index.php?pagename=templates-wordpress&pnum=$1',
    	'templates-wordpress/categorie/(\d+)/page/(\d+)' => 'index.php?pagename=templates-wordpress&catid=$1&pnum=$2',
    	'templates-wordpress/categorie/(\d+)' => 'index.php?pagename=templates-wordpress&catid=$1'
    );
    
    return $ftc_new_non_wp_rules + $rules;
    }
    
    add_filter('rewrite_rules_array', 'add_rewrites');
    add_action('admin_init', 'flush_rewrites');

    The problem is that WordPress doesn’t add this rules to the htaccess file BUT I can see with the Rewrite rules inspector plugin (available here : http://wordpress.org/extend/plugins/rewrite-rules-inspector/ ) that’s the rules seems to work good … :

    • templates-wordpress/page/(\d+) index.php?pagename=templates-wordpress&pnum=$1 other
    • templates-wordpress/categorie/(\d+)/page/(\d+) index.php?pagename=templates-wordpress&catid=$1&pnum=$2 other
    • templates-wordpress/categorie/(\d+) index.php?pagename=templates-wordpress&catid=$1 other

    But not on my htaccess file :

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Any help ?

    Thanks πŸ™‚

Viewing 1 replies (of 1 total)
  • Thread Starter UnPointZero

    (@unpointzero)

    Ok think I’ve found a fix, here’s the code :

    // Ajout rewrite rules
    function ftc_flush_rewrites() {
     global $wp_rewrite;
     $wp_rewrite->flush_rules();
    }
    
    function ftc_add_rewrites() {
     global $wp_rewrite;
     $ftc_new_non_wp_rules = array(
    	'templates-wordpress/page/(\d+)' => '/index.php?pagename=templates-wordpress&pnum=$1',
    	'templates-wordpress/categorie/(\d+)/page/(\d+)' => '/index.php?pagename=templates-wordpress&catid=$1&pnum=$2',
    	'templates-wordpress/categorie/(\d+)' => '/index.php?pagename=templates-wordpress&catid=$1'
     );
    
     $wp_rewrite->non_wp_rules = $ftc_new_non_wp_rules;
    }
    
    function add_rewrites_php($ruleswp) {
    global $wp_rewrite;
    $ftc_new_non_wp_rules = array(
    	'templates-wordpress/page/(\d+)' => 'index.php?pagename=templates-wordpress&pnum=$1',
    	'templates-wordpress/categorie/(\d+)/page/(\d+)' => 'index.php?pagename=templates-wordpress&catid=$1&pnum=$2',
    	'templates-wordpress/categorie/(\d+)' => 'index.php?pagename=templates-wordpress&catid=$1'
    );
    
    return $ftc_new_non_wp_rules + $ruleswp;
    }
    
    add_filter('rewrite_rules_array', 'add_rewrites_php');
    
    add_action('generate_rewrite_rules', 'ftc_add_rewrites');
    add_action('admin_init', 'ftc_flush_rewrites');

    Anyone can tell me if there’s a way to optimize that ?

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Rewriting custom url problem’ is closed to new replies.