Page 1 of 1

.htaccess change subdomain and subfolder to parameter

Posted: Mon May 25, 2009 4:04 am
by nakeddeveloper
I would like to have a .htaccess file that will passively redirect
subdomain.domain.com/folder (with or without a / at the end)
to
"http://www.domain.com/index.php?subdoma ... der=folder"

I would also like it leave it as it is when a file is requested.

Please help, I've seen similar stuff about but I think I just need it all spelling out for me... something in my head is about to pop...

Re: .htaccess change subdomain and subfolder to parameter

Posted: Mon May 25, 2009 5:23 am
by nakeddeveloper
For anyone who is interested, I have found what I believe is a more elegant solution by moving the functionality to php...
The .htaccess file just sends everything to index.php now...

Code: Select all

RewriteEngine On 
RewriteRule ^(.*)$ index.php
And this is my php in the index.php file

Code: Select all

<?php
$uri = $_SERVER['REQUEST_URI'];
$domain_parts = explode('.',$_SERVER['HTTP_HOST']); 
if (count($domain_parts) == 3 && $domain_parts[0]!= "www")
  {                         // make sure a subdomain is called 
    $subdomain = $domain_parts[0];
  }
?>
I may still need some help as there are likely going to be issues when refering to images or ajax scripts, watch this space...