1

I would to make a Regex (I use Nginx) to have something like this :

Example of output :

/m/signup
/en/signup
/fr/m/signup
/en/m/signup

I tried something like this :

rewrite ^/(m|(fr|en)|(fr|en)\/m)/(signup|otherpage)$ /$2.php?p=$1 last;

the parameter "p" should be either "m", or "en", or "fr", or "fr/m" for example.

but it doesn't want to work..

Any idea ?

2
  • What if you use ^/((?:fr|en|m)(?:/(?:fr|en|m))?)/(signup)$? It will also match /fr/fr/signup or /m/m/signup though - is it OK? Also, try ^/((?:en|fr)/m|m|(?:en|fr))/(signup)$. Or is the problem in capturing the language abbreviation? Commented Feb 15, 2016 at 9:07
  • thank you Wiktor, your second regex works perfectly! Commented Feb 15, 2016 at 9:15

1 Answer 1

1

You can use

^/((?:en|fr)/m|m|(?:en|fr))/(signup|otherpage)$

See the regex demo

I used this instead of (m|(fr|en)|(fr|en)\/m):

  • (?:en|fr)/m - either en or fr followed with /m
  • | - or...
  • m - just m
  • | - or...
  • (?:en|fr) - eitherenorfr`
Sign up to request clarification or add additional context in comments.

1 Comment

Thnak you very much Wiktor!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.