vjwilson
vjwilson

Reputation: 833

URL regex for sublinks in the main website

I want to create a regex for the URLs that I want to whitelist in WAF.

For the sub URL, example:

http://www.example.com/wp-admin/admin-ajax.php?action=aks_expt

and

http://www.example.com/wp-admin/admin-ajax.php?action=aks_expt&aks_ex1m_expt=1

I guess, I managed to put regex for the starting portion:

(https:\/\/www\.|http:\/\/www\.^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$)

to match up to http://www.example.com or https://www.example.com

but I am unsure how to be for the sublinks:

/wp-admin/admin-ajax.php?action=aks_expt

and

/wp-admin/admin-ajax.php?action=aks_expt&aks_ex1m_expt=1

I built one anyway but fails:

https:\/\/www\.|http:\/\/www\.^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$\/wp-admin\/admin-ajax\.php\?action\=aks\_expt

Upvotes: 0

Views: 180

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521194

Try the following regex:

(?:https?://www\.example\.com)?/wp-admin/admin-ajax\.php\?action=aks_expt(?:&aks_ex1m_expt=1)?

Demo

Explanation:

(?:https?:\/\/www\.example\.com)?           match optional leading http/https
                                            followed by domain
/wp-admin/admin-ajax\.php\?action=aks_expt  mandatory path
(?:&aks_ex1m_expt=1)?                       optional query parameter

Upvotes: 1

Related Questions