Stephan Whelan
Stephan Whelan

Reputation: 13

Simple Filename/Path Regex

I need to create a regex expression that I will use in a redirect plugin in wordpress.

I have a bunch of legacy URL's that look like this:

/article.php/281/19/0 
/article.php/383/20
/article.php/28/2/1

etc...

Essentially I want to create a regex that will strip off anything beyond the first set of numbers.

e.g. /article.php/281/19/0 transforms to /article.php/281

Upvotes: 1

Views: 121

Answers (2)

dawg
dawg

Reputation: 104111

You can do:

(^\/\w+\.\w+\/\d+)

Demo

Upvotes: 1

davcs86
davcs86

Reputation: 3935

For Yoast, you can use

REGEX: /(article\.php\/[0-9]+)/

NEWURL: /$1/

Based on: https://yoast.com/wordpress-seo-premium-1-1/

Upvotes: 0

Related Questions