WordPress Mod rewrite

I am trying to add a rule to wordpress so that anything like /src/test becomes /src?urn=test with the following rule.

add_action('init', 'add_src_url');
function add_src_url()
{
    add_rewrite_rule(
        '^src/([^/]*)$',
        'src/urn=$matches[1]',
        'top'
    );
}

Content of .htaccess file:

Read More
# 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

The above is not working. Mod Rewrite is enable. Is there any problem with the code ?

Related posts

1 comment

  1. Try like below and let me know:

    /* Add rewrite rule */
    
    function hotel_add_rewrite_rules() {
        add_rewrite_tag('%{custom_data_var}%', '([^/]*)');
        add_rewrite_rule('^{custom_name}/([^/]*)/?$', 'index.php?pagename={page_name}&{custom_data_var}=$matches[1]', 'top');
    }
    
    add_action('init', 'hotel_add_rewrite_rules');
    

Comments are closed.