lighttpd forum lighty > How to combine url.redirect and url.rewrite

Posted by Andreas Red
on 14.04.2008 20:43
Hi all!
I started with lighttpd today and I am totally surprised HOW fast it is.
But I have one problem i simply can not solve and I really hope one of 
you can please solve me that.

i have in my configuration-file:

$HTTP["host"] =~ "^server\.net" {
url.redirect = (
"^/(.*)$" => "http://www.server.net/$1"
)
}

url.rewrite = (
"^/city-([0-9]+).htm" =>
"/city.php?city=$1")

when i browse http://www.server.net/city-1.htm everythings working well.
when i browse http://server.net/city-1.htm i am forwarded to 
http://www.server.net/city.php?city=1

how do i need to combine my redirect-rule and my rewrite-rule that i am 
forwared to http://www.server.net/city-1.htm
Posted by Steve Graham
on 21.04.2008 22:17
Andreas Red wrote:
> Hi all!
> I started with lighttpd today and I am totally surprised HOW fast it is.
> But I have one problem i simply can not solve and I really hope one of 
> you can please solve me that.
> 
> i have in my configuration-file:
> 
> $HTTP["host"] =~ "^server\.net" {
> url.redirect = (
> "^/(.*)$" => "http://www.server.net/$1"
> )
> }
> 
> url.rewrite = (
> "^/city-([0-9]+).htm" =>
> "/city.php?city=$1")
> 
> when i browse http://www.server.net/city-1.htm everythings working well.
> when i browse http://server.net/city-1.htm i am forwarded to 
> http://www.server.net/city.php?city=1
> 
> how do i need to combine my redirect-rule and my rewrite-rule that i am 
> forwared to http://www.server.net/city-1.htm

I don't know if it will help, but try reversing those two directives. 
Rewrite first, then redirect.

Gram
Posted by Rhinofly Yin
on 04.05.2008 10:39
Steve Graham wrote:
> Andreas Red wrote:
>> Hi all!
>> I started with lighttpd today and I am totally surprised HOW fast it is.
>> But I have one problem i simply can not solve and I really hope one of 
>> you can please solve me that.
>> 
>> i have in my configuration-file:
>> 
>> $HTTP["host"] =~ "^server\.net" {
>> url.redirect = (
>> "^/(.*)$" => "http://www.server.net/$1"
>> )
>> }
>> 
>> url.rewrite = (
>> "^/city-([0-9]+).htm" =>
>> "/city.php?city=$1")
>> 
>> when i browse http://www.server.net/city-1.htm everythings working well.
>> when i browse http://server.net/city-1.htm i am forwarded to 
>> http://www.server.net/city.php?city=1
>> 
>> how do i need to combine my redirect-rule and my rewrite-rule that i am 
>> forwared to http://www.server.net/city-1.htm
> 
> I don't know if it will help, but try reversing those two directives. 
> Rewrite first, then redirect.
> 
> Gram

$HTTP["host"] =~ "^server\.net" {
url.redirect = (
"^/(.*)$" => "http://www.server.net/$1"
)
}

$HTTP["host"] =~ "^www\.server\.net" {
url.rewrite = (
"^/city-([0-9]+).htm" =>
"/city.php?city=$1")

}

would work for you.