Vishnu Vishnu - 1 year ago 84
PHP Question

Redirect the Url pattern ending with specialcharacter and number

My requirement is to redirect some of my urls which contains a 8 digit number and a special character at the end.

Example urls are given below

I am using pregmatch in php to find the patterns containing "-" and 8 digit number.

I tried the below code and it is not working for me. Is my pattern correct?

$result = preg_match("#.*/-\d{8}$#i", request_uri());

Answer Source

The following pattern will match any URL with a dash followed by 8 digits at the end. URLs with a special character at the end would not match.

$result = preg_match("/.*-\d{8}$/i", request_uri());

Demo here:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download