Title: Loop problem with Regex
Last modified: May 24, 2018

---

# Loop problem with Regex

 *  Resolved [mc_deimon](https://wordpress.org/support/users/mc_deimon/)
 * (@mc_deimon)
 * [8 years ago](https://wordpress.org/support/topic/loop-problem-with-regex/)
 * Hi. I’m trying to write an expression but I can not do it. Can somebody help 
   me? I need to make a URL like this:
 * [http://mydomain.com/author/name](http://mydomain.com/author/name)
 * It becomes this:
 * [http://mydomain.com/author/name/?type=ads](http://mydomain.com/author/name/?type=ads)
 * “name” is a variable.
 * I have tried with this:
 * Source URL: /author/(.*)
 * Target URL: [http://mydomain.com/author/$1/?type=ads](http://mydomain.com/author/$1/?type=ads)
 * But it does not work. A loop occurs:
 * [http://mydomain.com/author/name/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/](http://mydomain.com/author/name/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/?type=ads/)

Viewing 1 replies (of 1 total)

 *  [CEMBTW](https://wordpress.org/support/users/cembtw/)
 * (@cembtw)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/loop-problem-with-regex/#post-10347327)
 * It’s working correctly. The problem is that your target URL is also a match for
   your your source regex, so it just keeps on redirecting.
 * Play around with this test tool:
    [https://regex101.com/](https://regex101.com/)
 * Think about the possible permutations of the url you want to match and type them
   in the “Test String” section (leave off your domain), and put your target url
   in the “Substitution” section.
 * For example, `\/author\/(\w*)$` will match “/author/my_userNAME” and will not
   match the redirected “/author/my_userNAME?type=ads”.
 * But you also have to think about things like: What characters are allowed in 
   my author names? Do I need to account for trailing slashes? etc., account for
   those cases in your Test Strings, and rework your regex as needed.
    -  This reply was modified 7 years, 12 months ago by [CEMBTW](https://wordpress.org/support/users/cembtw/).

Viewing 1 replies (of 1 total)

The topic ‘Loop problem with Regex’ is closed to new replies.

 * ![](https://ps.w.org/redirection/assets/icon-256x256.jpg?rev=983639)
 * [Redirection](https://wordpress.org/plugins/redirection/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/redirection/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/redirection/)
 * [Active Topics](https://wordpress.org/support/plugin/redirection/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redirection/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redirection/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [regex](https://wordpress.org/support/topic-tag/regex/)

 * 1 reply
 * 2 participants
 * Last reply from: [CEMBTW](https://wordpress.org/support/users/cembtw/)
 * Last activity: [7 years, 12 months ago](https://wordpress.org/support/topic/loop-problem-with-regex/#post-10347327)
 * Status: resolved