0

I am trying to solve a rewriting issue. Basically

After quite a bit of research, I came up with this custom rewrite rules:

    $category     = 'category';
    $page_slug    = 'florida';
    $title        = 'index.html';

    add_rewrite_rule(
         '^'. '/' .$category. '/' .$page_slug . '/' . $title,
         'index.php?page_id='.$page_id, 
         'top'
    );

    add_rewrite_rule(
        '^'. '/' .$category. '/' .$page_slug . '/page/([0-9]+)?/index.html',
        'index.php?page_id='.$page_id,
        'top'
    );

What I want to achieve:

From: http://domain.com/category/someCategory/
To: http://domain.com/category/someCategory/index.html

Apply: When the user is on the first page

From: http://domain.com/category/florida/page/n
To: http://domain.com/category/florida/page/n/index.html

Apply: When the user is on (n>1) page

Is it possible to do what I am looking for?

Thank you for your help!

UPDATE:

I managed to solve it with a little javascript by doing this:

     $(document).ready(function(){
                window.history.replaceState(null, null, "");
                let  t = window.location.href;
                let s  = "";
                s = t;
                console.log("URL: "+s);
                if(!(s.includes("/index.html")))
                {
                   window.history.replaceState(null, null, s+"/index.html");

                }
                else
                {
                    $.ajax({
                        type: 'HEAD',
                        url: s,
                        success: function() {
                          ;


                        },
                        error: function(jqXHR, status, exception) {
                           if(jqXHR.status == 404)
                           {
                              window.history.replaceState(null, null,s.split('/index.html')[0]);
                              window.location = s.split('/index.html')[0];

                               }
                        }
                    });
                }


    }); 
  • It looks like you would like to add index.html at the end of the default category link. Is that so? – nmr Jul 17 '19 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.