• hima.shah

    (@himashah)


    How Can we rewrite url in Htaccess?

    Suppose My URL is https://localhost/yaclick/yahclick/partners/?country=new-zealand,
    Here Partners is my page name but i have no page name having new-zealand
    and I want to display
    https://localhost/yaclick/yahclick/partners/new-zealand.

    I have tried with Following Rules add in Htaccess.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^partners/(\w*)$ partners/?country=$1 [NC,L]
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    But its not Working

    even I have tried with add_rewrite_rule in Functions.php

    I have added following code in Functions.php.
    1st way
    add_filter( ‘query_vars’, ‘wpse12965_query_vars’ );
    function wpse12965_query_vars( $query_vars )
    {
    $query_vars[] = ‘var1’;
    return $query_vars;
    }
    add_action( ‘init’, ‘wpse12065_init’ );
    function wpse12065_init()
    {
    add_rewrite_rule(
    ‘yahclick/partners(/([^/]+))?/?’,
    ‘index.php?pagename=partners&var1=$matches[2]’,
    ‘top’
    );
    }

    2nd way

    function fcars() {

    add_rewrite_rule(‘partners/[/]?([a-zA-Z-]*))$’, ‘index.php?pagename=partners&var1=$matches[1]’);

    add_rewrite_tag(‘%var1%’, ‘[a-zA-Z]+’);

    }

    add_action(‘init’, ‘fcars’);

    But both are not working.

    So what i forgot to write here can you please Help me?

    # END WordPress

  • The topic ‘Rewrite Url In WordPress’ is closed to new replies.