jeudi 5 mai 2016

Wordpress rewrite API, add_rewrite_rule issue

I have installed wordpress in my local machine: So my home_url is http://localhost/wordpress (Have not created any virtual host entry)

I have created a page named test with page_id = 19. Now I need to use the rewrite as following:

when there will be any request as http://localhost/wordpress/group/abc, It should be converted to http://localhost/wordpress/?page_id=19&group=abc

My .htaccess:

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

# END WordPress

What I tried:

 add_action('init', function() {
     global $wp_rewrite; 
     $wp_rewrite->flush_rules();
     add_rewrite_rule('^group/([^/]+)', 'index.php?page_id=19&group=abc', 'top');
    add_rewrite_tag('%group%', '[A-Za-z]+');
 });

But whenever I am trying to access http://localhost/wordpress/group/abc I am getting 404 error.

Please suggest, am I doing any wrong .

Thank you in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire