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. Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/ Share on other sites More sharing options...
RussellReal Posted February 3, 2010 Share Posted February 3, 2010 [^\.]+?\.domain.com that should work Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1005850 Share on other sites More sharing options...
waverider303 Posted February 3, 2010 Author Share Posted February 3, 2010 didnt seem to work correctly. Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1006212 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 Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1006591 Share on other sites More sharing options...
RussellReal Posted February 4, 2010 Share Posted February 4, 2010 lolz.. "/^[^\.]+?\.domain.com$/" Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1006596 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 .). Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1006987 Share on other sites More sharing options...
RussellReal Posted February 4, 2010 Share Posted February 4, 2010 (?:[^\.]+\.)?domain.com that works lolz Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1006990 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? Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1007091 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 Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1007194 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" Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1007559 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#"; Link to comment https://forums.phpfreaks.com/topic/190692-domain-names-preg_match/#findComment-1007561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.