wordpress url rewrite Query Var to Static url

i have urls like these:

http://animup.net/manga/bara-no-maria/

and have some url parameters

http://animup.net/manga/bara-no-maria/?chp=1
http://animup.net/manga/bara-no-maria/?chp=2
http://animup.net/manga/bara-no-maria/?chp=3
....

is there anyway to have urls like these:

http://animup.net/manga/bara-no-maria/chp-*/

I found my solution: here is my code:

    add_action('init','mangareader_init');
    function mangareader_init() {
      global
      $wp,$wp_rewrite;
      $wp->add_query_var('chp');
      $wp_rewrite->add_rule('manga/([^/]+)/c([^/]+)',
        'index.php?post_type=manga&name=$matches[1]&chp=$matches[2]', 'top');
      // Once you get working, remove this next line
      //$wp_rewrite->flush_rules(false);  
    }

Answer

Okay lets try this (didn’t want to put it “just as comment” because of the code.

In your comment you gave still no answer on a “possible caching issue” but still. Maybe, just maybe this part of code in .htaccess could help. Be aware this code could mess up more then wished! (Please read what is explained! follow that link for more information please).

This code before the line # BEGIN WordPress in .htaccess. Source code found here.

RewriteEngine On
RewriteCond %{QUERY_STRING} !=""         #if there is a query string
RewriteCond %{QUERY_STRING} !^p=.*       #wordpress users: allow post tempalinks
RewriteCond %{REQUEST_URI} !^/wp-admin.* #wordpress users: don't break admin
RewriteRule ^(.*)$ /$1? [R=301,L]        #remove query string

I also found some answers on Stackoverflow itself. Maybe there you also find some source code you could use/try. RewriteCond/RewriteRule for removing query strings from URLs

Another answer which maybe could help is found here: also stackoverflow

Attribution
Source : Link , Question Author : user1489083 , Answer Author : Community

Leave a Comment