WordPress.org

Forums

Redirection
Regex for simple redirection (9 posts)

  1. James.v
    Member
    Posted 1 year ago #

    I am trying to set up a redirection but cannot get the regex right.

    I have hundreds of 404's for URL's like

    /folder/anythinghere
    /folder/old-file.php
    /folder/not-here/gone

    All I want to do is to redirect them to

    /folder/

    with creating an infinite loop.

    I have tried redirecting with /folder/(.*) to /folder/ and several other variations but cannot get this to work without creating a loop.

    Does anyone have a simple regex to do this?

    https://wordpress.org/plugins/redirection/

  2. jrf
    Member
    Posted 1 year ago #

    Use /folder/(.+) instead and you should be fine ;-)

    .* means 0 or more characters
    .+ means 1 or more characters, so that should avoid the infinite loop

  3. jrf
    Member
    Posted 1 year ago #

    Actually you don't even need the brackets and you may want to anchor to the beginning of the url, so use the below instead:

    ^/folder/.+

    Should match:
    /folder/anythinghere
    /folder/old-file.php
    /folder/not-here/gone

    Will prevent matching on:
    /folder/
    /some/other/folder/
    /some/other/folder/file.ext

  4. nathanpocock
    Member
    Posted 1 year ago #

    The last comment almost worked for me, I currently intercept:

    /mantis(.*)

    What I am finding is that this does match:

    /mantis
    /mantis/
    /mantis/page

    ... but not /mantis/page.php

    For some reason, the .php extension throws this error:

    "Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.
    Apache/2.2.26 (******) Server at ************ Port 443"

    Any suggestions on how to prevent the .php extension causing this crash would be appreciated. Thanks.

  5. jrf
    Member
    Posted 1 year ago #

    Strange, it should not do that. Can you try to see if this works better ?

    /mantis(.*)(\.php)?$

  6. nathanpocock
    Member
    Posted 1 year ago #

    Unfortunately, the result is the same: 500 Internal Server Error

    What I've found is that if ".php" is simply present, then the 500 error will occur.

    I also tried your suggestion without the $ symbol and it didn't help either.

    This is the URL I'm trying:
    https://mydomain.org/mantis/main_page.php
    http://mydomain.org/mantis/view.php?id=1019

  7. jrf
    Member
    Posted 1 year ago #

    Hang on... you are using the * again... causing you to get into the infinite redirect loop....

  8. nathanpocock
    Member
    Posted 1 year ago #

    I'm sorry, but I didn't understand the last comment.

    The regex I'm using is:
    /mantis(.*)(\.php)?$

    There is only one * in there. So the 500 error is an infinite redirect loop?

    Any other suggestions? (Your help is really appreciated)

  9. jrf
    Member
    Posted 1 year ago #

    I believe it might be.

    You're probably better off adding a rule for this to your .htaccess file instead of using the redirect plugin.

    Are you familiar with editing .htaccess ?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Redirection
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic