Support » Plugin: Redirection » My first regex, need opinions

  • Resolved ctrlaltdelete

    (@ctrlaltdelete)


    Hello, i made my first regex. I read the documentation and googled a bit and came up with one. It works. But i wanna know the opinion of someone with regex knowledge.

    What it does is redirects paginated archives to parent. that is:
    /page/2/
    from the homepage or from custom types archives.
    It also “saves” the custom post type slug (if present) and eventual query parameters (if present).

    This is the regex, source:
    \/([^\/^.]*)\/?page\/[0-9]{1,3}\/(.*)
    TARGET URL
    /$1/$2

    TEST URLS:

    /page/2/
    /custom-type/page/40/
    /custom-type/page/999/?language=english&filter_genre=action

    Please tell me what you think if there’s something obviously wrong, thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • ctrlaltdelete

    (@ctrlaltdelete)

    I’ve noticed a problem.
    I want this to 301 redirect people that come from google or elsewhere or that inserts the paginated url in the browser directly.

    Because i have not removed pagination. it’s just handled by Jquery now via POST method.
    This 301 breaks Jquery.

    Could we have the option to ignore POST? Like:
    https://stackoverflow.com/questions/22342141/htaccess-do-not-rewrite-url-if-post-data

    Else i’ll have to move to htaccess. =?

    Plugin Author John Godley

    (@johnny5)

    I would be surprised if your ajax request is using a POST, and if it is then it should probably use a GET instead. You can use a 307 redirect to indicate the request method is passed along.

    ctrlaltdelete

    (@ctrlaltdelete)

    Hi, you are right it is get. I tried with 307 and jquery stops updating the content.

    This is my code to load paginated on same url:

    <script>
    (function ( $ ) {
    		
    	$("body").on("click", "a.page-numbers", function(e) {
        e.preventDefault();
        $("#main").load($(this).attr("href") + " #main");
    	$('html, body').animate({
                scrollTop: $("#content").offset().top - 70
            }, "slow"); 
    });
    
    }(jQuery));
    </script>

    If i set the redirect this won’t work.
    When i disable the redirect this works again.
    What can i do?

    Plugin Author John Godley

    (@johnny5)

    If it is a GET request then you shouldnt need to do anything. This doesn’t look right:

    $(this).attr(“href”) + ” #main”

    You have a space in there, and #main won’t get sent to the server anyway.

    ctrlaltdelete

    (@ctrlaltdelete)

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘My first regex, need opinions’ is closed to new replies.