Jump to content

Domain Names preg_match


waverider303

Recommended Posts

1. I am trying to match all subdomains of my .com to get redirected to a single folder

 

2. The input data will be $_SERVER["SERVER_NAME"]; so (*.hainymedia.com) * being anything.

So that if they goto f2hd4sak.hainymedia.com it will watch it. I am using a Switch conditional so if it find *.hainymedia.com it will redirect to the same folder.

 

I tried to use "\b[A-Z0-9._%+-]+.hainymedia.com" but I am very new to regex and I dont know what I am doing.

 

Link to comment
https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/
Share on other sites

What is "/^[^\.]+?\." searching for? What I am using to get the domain is $_SERVER['SERVER_NAME']; so it will look something on these lines depending on what they type into the url:

 

hainymedia.com

www.hainymedia.com

subdomain.hainymedia.com

test.hainymedia.com

 

and I want to do a preg_match() to find *(meaning wildcard) .hainymedia.com or even just hainymedia.com (missing the leading .).

<?php
$server = $_SERVER["SERVER_NAME"];
$pattern = "(?:[^\.]+\.)?example.com";
echo "Server is: $server <br />";
switch ($server) {
case preg_match($pattern, $server):
	echo "Worked";
	break;
/*case "example.com":
	header('Location: /~root_folder');
	break;
case "www.example.com":
	header('Location: /~root_folder');
	break;*/
}
?>

 

This is what I have and i am getting "UnKnown modifier errors"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.