-1

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?

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236
  • Why don’t you extract the language from the HTTP host with PHP (`$_SERVER['HTTP_HOST']`)? – Gumbo Dec 27 '09 at 17:02
  • @Gumbo - Without different subdomains search engines don't get that there are more languages on this site. – Tom Smykowski Dec 29 '09 at 09:39
  • 2
    @tomaszs: How about putting the language identifier into the URL path instead like `http://example.com/en/…`? And don’t forget proper language declaration in HTTP and HTML. – Gumbo Dec 29 '09 at 20:52

3 Answers3

6

Try this:

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

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
  • 2,465
  • 18
  • 20
  • `&language=en` in `http://example.com/&language=en` is part of the URL path and not part of the URL query. – Gumbo Jan 04 '10 at 16:13
  • True. You can use “?” in place of “&” but that breaks if the URL already has parameters. Example: `http://en.example.com/?param1=12345 -> http://example.com/?param1=12345?language=en` Do you need to handle URLs with query string parameters already? – Shane O'Grady Jan 04 '10 at 17:05
0

try following.. if it works for you..

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

amar4kintu
  • 831
  • 11
  • 21
  • 32