charlesg Posted October 3, 2009 Share Posted October 3, 2009 I had my server company setup wild card subdomains, so anything.mysite.com will work and display the same content as www.mysite.com. Now I need some .htaccess magic setup to route any sub domain to the www.mysite.com (and all URI segments), but keep the subdomain in the location bar. Unfortunately, I'm not a regex guru. Does anyone know how to do this who is willing to help me out please? Examples - I need all of these formats to work like this... hello.mysite.com -> www.mysite.com, but display hello.mysite.com hello.mysite.com/cool/site -> www.mysite.com/hello/site, but display hello.mysite.com/cool/site hello.again.mysite.com -> www.mysite.com, but display hello.again.mysite.com hello.again.mysite.com/cool/site -> www.mysite.com/cool/site, but display hello.again.mysite.com/cool/site Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 Well, i'm not an expert. but this might help you out. RewriteEngine On RewriteCond %{HTTP_HOST} ^(.*).example.com RewriteRule ^(.*)$ http://example.com [R=301,L] Quote Link to comment Share on other sites More sharing options...
charlesg Posted October 3, 2009 Author Share Posted October 3, 2009 Thanks, but it didn't do it. It just routes double subdomains (a.b.domain.com) to the primary domain and changes the url Quote Link to comment Share on other sites More sharing options...
charlesg Posted October 4, 2009 Author Share Posted October 4, 2009 I found this on a forum thread, but it didn't seem to work either. Anyone else got an idea? RewriteCond %{ENV:REDIRECT_SUBDOMAIN} ="" RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.domain\.com\.?(:80)?$ [NC] RewriteCond %{DOCUMENT_ROOT}/%1 -d RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L] RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L] Quote Link to comment Share on other sites More sharing options...
nrobi Posted October 4, 2009 Share Posted October 4, 2009 It's a bandaid fix but I use it to separate layout from content in my website. My .htaccess routes all http errors to a particular script. This script displays either the requested webpage or a custom error message. It works because the URI_REQUEST... HTTP_REQUEST... can't remember the name of it atm but that value is still in the $_SERVER array after .htaccess reroutes the request to your script. For example... someone types/clicks a link with http://www.mydomain.com/somelink.php 404 error is generated and redirected script looks at $_SERVER variable and parses request if file exists it is included, if not 404 error page displayed This URL in the browser will be whatever the user typed or the HREF value. Quote Link to comment Share on other sites More sharing options...
nrobi Posted October 4, 2009 Share Posted October 4, 2009 Here's the beginning of the code from my "master" page: $end = strrpos($_SERVER['REQUEST_URI'],'.'); $page = $_SERVER['DOCUMENT_ROOT'].substr($_SERVER['REQUEST_URI'],0,$end).'.iphp'; if(file_exists($page)) { header("HTTP/1.x 200 OK\r\n"); $require = true; } If you don't do the header you'll send out the 404 error as a response. And when using header() remember NO OUTPUT whatsoever before it's call.....not even a newline. You just have to modify it to parse it to your needs.... mine are pretty simple as you can see. 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.