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
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 .).

Link to comment
Share on other sites

<?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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.