Regex for simple redirection (9 posts)

  1. James.v
    Posted 2 years 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


    All I want to do is to redirect them to


    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?


  2. jrf
    Posted 2 years 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
    Posted 2 years 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:


    Should match:

    Will prevent matching on:

  4. nathanpocock
    Posted 2 years ago #

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


    What I am finding is that this does match:


    ... 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
    Posted 2 years ago #

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


  6. nathanpocock
    Posted 2 years 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:

  7. jrf
    Posted 2 years ago #

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

  8. nathanpocock
    Posted 2 years ago #

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

    The regex I'm using is:

    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
    Posted 2 years 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