• Resolved mdotk

    (@mdotk)


    Hello, I’ve noticed in my 404 logs that a strange string is being added to some URLs and causing a 404:

    number>;crid=1833;check_container=true

    Is there a way to wildcard any match so that the plugin just strips off that string and 301s to the proper URL. ie example.com/post/number>;crid=1833;check_container=true goes to example.com/post/

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author John Godley

    (@johnny5)

    Sure, you can use a regular expression to match that particular pattern. If it always happens at the end of URL you could use this as the source:

    number>;crid=1833;check_container=true$

    Thread Starter mdotk

    (@mdotk)

    Sorry what would be the regular expression?

    Are you saying I need one redirect per URL on my website?

    I was hoping for something like:

    1. In the top box enter “*/number>;crid=1833;check_container=true$”
    2. In the bottom box enter “*”

    Thread Starter mdotk

    (@mdotk)

    Hi again, in fact even when I manually add the URLs to redirect, it still 404s.

    It seems like there is characters in that string “number>;crid=1833;check_container=true$” that stop the redirect working. I discovered another such string too “[object Object]”

    In “[object Object]”, the brackets will have to be escaped as “\[object Object\]”
    All the characters in your “number” url should be safe, though.
    Use this tool to test various regex matches:
    https://regex101.com

    Thread Starter mdotk

    (@mdotk)

    Thank you, I am still really struggling to get matches.

    I made a regex (box ticked) rule like /directory/.* redirecting to /directory/ and then that page /directory/ goes into a redirect loop and won’t display. Chrome says “XXX has redirected you too many times”

    Also, anything I put in like /post-abc/number>;crid=1833;check_container=true$ redirecting to /post-abc/ also still returns a 404

    I exported my settings, deleted and reinstalled the plugin and looked for any duplicates and still these problems persist.

    • This reply was modified 8 years, 4 months ago by mdotk.

    @mdotk

    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)

    So /directory/ will always match your pattern of \/directory\/.* (remember to escape special characters) and loop.

    If you want all characters after /directory/ removed, then you could do something like \/directory\/\S.* or \/directory\/\S+. Try it in regex101, and hover over each part to see what they would accomplish.

    You can also get more information about what is happening during a redirect loop with this tool: http://redirectcheck.com/index.php

    Thread Starter mdotk

    (@mdotk)

    @cembtw thanks that is really helpful, I have got it working now

    I did some exploring on that site and it seems you can substitute out things. So I tried

    (number%3E;crid=1833;check_container=true34234)+

    Which should capture the text I want to delete/remove from the URL string, but then I can’t work out how to “redirect it” to whatever URL preceeded that string. This would mean that instead of doing individual redirects for every single post, I could just have one statement/rule that gets rid of that string.

    • This reply was modified 8 years, 4 months ago by mdotk.

    You could have another capture group to collect the text before our bad string:
    ^(.*)(number>;crid=1833;check_container=true)$

    So now we have two capture groups, which the plugin treats as “$1” and “$2”, and can set the target URL as: $1.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Weird string causing 404s’ is closed to new replies.