WordPress.org

Forums

[resolved] Need help with add_rewrite_rule (8 posts)

  1. Steven
    Member
    Posted 4 years ago #

    My current link is this:
    http://www.norwegianfashion.no/designers/?designer=Batlak-og-Selvig&bid=9

    What I want is this
    http://www.norwegianfashion.no/designers/Batlak-og-Selvig/

    I'm trying to use add_rewrite_rule() to achieve this.
    I found this site that wxplains it pretty good: http://www.prodeveloper.org/create-your-own-rewrite-rules-in-wordpress.html

    But it's not working :(

    function add_rewrite_rules( $wp_rewrite )
    {
        $new_rules = array(
            '('.$template_page_name.')/designers/(.*?)/?([0-9]{1,})/?$' => 'designers.php?designer='.
            $wp_rewrite->preg_index(1).'&bid='.
            $wp_rewrite->preg_index(2)
        );
           // Always add your rules to the top, to make sure your rules have priority
        $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }
    add_action('generate_rewrite_rules', 'add_rewrite_rules');
    
    function query_vars($public_query_vars) {
    
        $public_query_vars[] = "designer";
        $public_query_vars[] = "bid";
        return $public_query_vars;
    }
    add_filter('query_vars', 'query_vars')

    What am I doing wrong?

  2. Alex and Anthony
    Member
    Posted 4 years ago #

    Before you do any of this Bacup your WordPress files and Database
    Just add the following code to the .htaccess file in the root of the wordpress install.

    RewriteEngine On
    RewriteRule ^designers/([^/]*)/([^/]*)$ /designers/?designer=$1&bid=$2 [L]

    then your page should be something like
    http://www.norwegianfashion.no/designers/Batlak-og-Selvig/9

  3. Steven
    Member
    Posted 4 years ago #

    Why do I have to backup files and DB?

    The URL is still the same when I'm testing on my local pc.
    I'm using .com and point the DNS to localhost.

  4. Alex and Anthony
    Member
    Posted 4 years ago #

    i ask you to backup because anything can go wrong.

    try it on the live site and see what it looks like,
    just this time go to
    http://www.norwegianfashion.com/designers/Batlak-og-Selvig/9

  5. Curtiss Grymala
    Member
    Posted 4 years ago #

    @spstieng - If the .htaccess changes don't work, you can try the instructions in http://www.htmlcenter.com/blog/wordpress-creating-custom-permalinks-for-plug-ins/ to see if those help.

  6. Steven
    Member
    Posted 4 years ago #

    @Curtiss: I don't think I understand what I need to do out from that article :(

    I've tried several more variations. but without any luck whatsoever :(

    I'll be a very happy man if someone could help me with this.

  7. Steven
    Member
    Posted 4 years ago #

    I've got an another discussion on this topic here: http://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule/5478#5478

    I've tried so many solutions, but nothing seems to work :(

  8. Steven
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic