tags:

views:

94

answers:

2

Hi i need a very quick fix in a mod_rewrite expresion for drupal we have

  RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

But i need to redirect the value of the subdomain in get too so i need something that will give:

  RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?subdomain=THE SUBDOMAIN HERE&q=$1 [L,QSA]

Dont know how to do it, please help!

A: 

You don't really need the subdomain in the query string.

The subdomain can be found in PHP in $_SERVER['SERVER_NAME'].

PHP documentation says:

'SERVER_NAME'
    The name of the server host under which the
    current script is executing. If the script
    is running on a virtual host, this will be
    the value defined for that virtual host.
gnud
+4  A: 

Trying this again, for some reason my code isn't rendering properly.

RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule ^(.*) index.php?subdomain=%1&q=1 [L,QSA]

Based off of some forum posts I found here.

Beau Simensen
Note that if the domain is www.foo.domain.com subdomain will be passed www.foo
Vinko Vrsalovic
I would DRY up the REQUEST_URI condition: !\.(gif|jpg|png|css|js|php)$
PEZ