Alex Wiebogen
Alex Wiebogen

Reputation: 352

Optional / on end of an URL

I found out, today that its not the same if i open my URL with / on end or not for the rewrite rule.

# Pokedex
rewrite (?i)^\/Pokemon-Go-Pokedex\/$            /i.php?p=pokedex last;
rewrite (?i)^\/Pokemon-Go-Pokedex\/+([A-Za-z0-9]+)$     /i.php?p=pokedex&pokemon=$1 last;

If i open now domain.com/Pokemon-Go-Pokedex/ everything works. But domain.com/Pokemon-Go-Pokedex doesnt. Now i search a way, to make the / optional.

What i tryed (but failed by the nginx-config-test)

rewrite (?i)^\/Pokemon-Go-Pokedex+([\/]){0,1}$
rewrite (?i)^\/Pokemon-Go-Pokedex+([\/]{0,1})$

On RegExr.com this (//Pokemon-Go-Pokedex+[/]{0,1}) works, bot not in the config, so i need help.

Upvotes: 0

Views: 68

Answers (1)

chris85
chris85

Reputation: 23880

The ? make the previous character/group optional.

rewrite (?i)^\/Pokemon-Go-Pokedex\/?$

Upvotes: 2

Related Questions