Regex to detect a proper permalink?

Posted by Fedor on Stack Overflow See other posts from Stack Overflow or by Fedor
Published on 2010-04-08T16:08:43Z Indexed on 2010/04/08 16:43 UTC
Read the original article Hit count: 393

Filed under:
|

These permalinks above are rerouted to my page:

page.php?permalink=events/foo
page.php?permalink=events/foo/
page.php?permalink=ru/events/foo
page.php?permalink=ru/events/foo/

The events is dynamic, it could be specials or packages.

My dilemma is basically; I need to detect an empty link in order so I can feed a robots no index meta tag in the case of:

page.php?permalink=events
page.php?permalink=events/
page.php?permalink=ru/events/
page.php?permalink=ru/events

I can't use a simple pattern such as [a-zA-Z]+\/?(.+)/ since it won't work on the i18n permalinks.

What regex could I use which would detect this, using $_GET['permalink'] as the reference to the permalinks? And avoid false positives?

Update:

Empty link means there's no fragment after the "events/" part. These are empty:

page.php?permalink=events
page.php?permalink=events/
page.php?permalink=ru/events/
page.php?permalink=ru/events

© Stack Overflow or respective owner

Related posts about php

Related posts about regex