• Resolved flizzywp

    (@flizzywp)


    Hello,

    I use the following regex for a redirect right now:

    /code-examples/android/(.*)
    /tutorials/android/$1/

    Is there a way to redirect just /code-examples/ (without android/) to the 2nd URL as well (with a placeholder after that)? From my logic, this would break the first redirect, because then it would send /code-examples/android/ to /code-examples/android/android

    • This topic was modified 5 years, 6 months ago by flizzywp.
    • This topic was modified 5 years, 6 months ago by flizzywp.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter flizzywp

    (@flizzywp)

    As an example.

    /code-examples/android/page1

    and

    /code-examples/page1

    should both go to

    /tutorials/android/page1

    I’d try to create 2 redirects and give them different positions. Since only one redirect is triggered by URL, it should be an order so that the second redirect is only triggered if the first isn’t. For example:

    Source: ^/code-examples/android/(.*)
    Target: /tutorials/android/$1/
    Position: 100
    Source: ^/code-examples/(.*)
    Target: /tutorials/android/$1/
    Position: 101

    I hope it works. Good luck!

    • This reply was modified 5 years, 6 months ago by CB.
    Thread Starter flizzywp

    (@flizzywp)

    Oh, I didn’t know I could do that with order! Thank you!

    Thread Starter flizzywp

    (@flizzywp)

    Actually, it only works IF something is behind the last slash, otherwise it doesn’t work. https://codinginflow.com/code-examples/android
    redirects me to /code-examples/android/android.
    But only WITHOUT the trailing slash. It redirects properly with the trailing slash, but it redirects me to /tutorials/android// (with 2 trailing slashes). Any idea what could be the reason?

    /code-examples/ also does only work with a trailing slash.

    It seems like it NEEDS something to put into the placeholders. How can I make it support redirects if the placeholders are empty?

    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    • This reply was modified 5 years, 6 months ago by flizzywp.
    Thread Starter flizzywp

    (@flizzywp)

    If someone is interested, the following combined regex solved my problems:
    /code-examples(?:/android|)(?:/?(.*)|\b)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Help with a regex’ is closed to new replies.