Noor
Noor

Reputation: 20140

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:

# 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 ?

Upvotes: 1

Views: 49

Answers (1)

Kausha Mehta
Kausha Mehta

Reputation: 2928

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');

Upvotes: 2

Related Questions