views:

353

answers:

3

I would like redirect addresses that start with:

en.example.com/somefile.php

to:

example.com/somefile.php?language=en

Using mod_rewrite module in lighttpd. Until now I got this:

$HTTP["host"] =~ "^en\.(.*)\.com$" {
        url.rewrite-once = (
                "^/(.*)"
                =>
                "/$1?language=en"
        )
}

But this does not seem to be working. What to do to make this work?

A: 

Hello.. try following.. if it works for you..

$HTTP["host"] =~ "^en.([^.]+.com[a-z0-9-]+.php)$" { url.rewrite-once = ( "^/(.*)" => "/$1?language=en" ) }

amar4kintu
it does not work :(
tomaszs
were you able to solve your problem?
amar4kintu
+6  A: 

Try this:

$HTTP["host"] =~ "^en\.([^/.]+)\.com$" {
    url.rewrite-once = (
        "^/([^?]*)(\?(.*))?" => "http://%1/$1?language=en&$3"
    )
}
Gumbo
+3  A: 

Try this

$HTTP["host"] !~ "^(en|fr)\.([^.]+\.com)$ {
    url.rewrite-once = (
      "^/(.*)" => "http://%2/$1&language=%1" 
    )
  }

This should rewrite subdomains en. and/or fr. to whatever domain (including the TLD) with the URL string intact, and append the language parameter.

Examples:

http://en.example.com            -> http://example.com/&language=en
http://fr.example.com/directory/ -> http://example.com/directory/&language=fr
Shane O'Grady
Gumbo
Shane O'Grady
I didn’t ask this question, I just edited it.
Gumbo