Khor Shuqi

New DNS Zone on Facebook?

Have you noticed recently that when you browse Facebook on your laptop, it’s no longer “www.facebook.com” but “web.facebook.com”?

I’m not sure if this subdomain has existed earlier in other places, but I have only just seen in Malaysia since December 2022.

The Impact

If you’re just a regular user, then it might not affect you at all.

But if you’re a web developer, especially one who likes to use REGEX (Regular Expression) to validate strings on your websites, then your sites might accidentally block users to enter certain Facebook URL.

For example, I have used this REGEX on one of my sites:

if (!preg_match("/^https?:\/\/((m|mobile|www)\.)?facebook\.com/i", $url)) {
  // not a facebook URL
}

…which will not match the new subdomain.

New REGEX for Facebook URL Validation

Now, to accommodate the new Facebook subdomain, I just need to add it into the bracket in the middle (separated by a pipe symbol):

if (!preg_match("/^https?:\/\/((m|mobile|www|web)\.)?facebook\.com/i", $url)) {
  // not a facebook URL
}

Or, if you prefer the lazy way (I mean future-proof), just match any alphabet in the subdomain:

if (!preg_match("/^https?:\/\/([a-z]+\.)?facebook\.com/i", $url)) {
  // not a facebook URL
}

That’s it, hope it helps!