waverider303 Posted February 2, 2010 Share Posted February 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 3, 2010 Share Posted February 3, 2010 [^\.]+?\.domain.com that should work Quote Link to comment Share on other sites More sharing options...
waverider303 Posted February 3, 2010 Author Share Posted February 3, 2010 didnt seem to work correctly. Quote Link to comment Share on other sites More sharing options...
waverider303 Posted February 4, 2010 Author Share Posted February 4, 2010 I get this error: Warning: preg_match() [function.preg-match]: Unknown modifier '+' in /volume1/web/index.php on line 15 Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 4, 2010 Share Posted February 4, 2010 lolz.. "/^[^\.]+?\.domain.com$/" Quote Link to comment Share on other sites More sharing options...
waverider303 Posted February 4, 2010 Author Share Posted February 4, 2010 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 .). Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 4, 2010 Share Posted February 4, 2010 (?:[^\.]+\.)?domain.com that works lolz Quote Link to comment Share on other sites More sharing options...
cags Posted February 4, 2010 Share Posted February 4, 2010 If the OP wants the subdomain what on earth is the point of creating a non-capture group? waverider303, can you show us a complete line of code so that we know exactly what your talking about? Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 5, 2010 Share Posted February 5, 2010 cags, hes not trying to get the value hes trying to redirect all subdomains to a single folder, no use in capturing data that won't be used Quote Link to comment Share on other sites More sharing options...
waverider303 Posted February 5, 2010 Author Share Posted February 5, 2010 <?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" Quote Link to comment Share on other sites More sharing options...
cags Posted February 5, 2010 Share Posted February 5, 2010 The preg_match function uses the PCRE engine, as such the pattern requires delimiters... $pattern = "#(?:[^\.]+\.)?example.com#"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.