[Solved] rewrite with redirect issue
Added by skinniepuppie over 5 years ago
I'm using url.rewrite-once to have "^/favicon.png$" => "/media/favicon.png"
It works fine with http to request http://hostname/favicon.png, but when using url.redirect from http to https "^/(.*)" => "https://hostname/$1"
It has a request from http://hostname/favicon.png go to https://hostname/media/favicon.png
I also use webpy with fastcgi and when going to http://hostname/ip it redirects to https://hostname/code.py/ip which gives a "not found", same issue.
Replies (11)
RE: rewrite with redirect issue - Added by gstrauss over 5 years ago
If you want redirects to take place before rewrites, then list "mod_redirect" before "mod_rewrite" in server.modules.
RE: rewrite with redirect issue - Added by skinniepuppie over 5 years ago
Looks like it is, I didn't change anything, and I am still having the issue. Tried to swap it just to see, and still happening.
server.modules = (
"mod_access",
"mod_alias",
# "mod_auth",
# "mod_authn_file",
# "mod_evasive",
"mod_redirect",
"mod_rewrite",
# "mod_setenv",
# "mod_usertrack",
"mod_openssl",
)
RE: rewrite with redirect issue - Added by gstrauss over 5 years ago
That snippet of your config is not very helpful.
I just looked through the code and mod_rewrite handles the URI earlier than mod_redirect, so the order does not matter. My mistake.
If you don't want certain URI's rewritten, the you'll have to match those in a condition and redirect those. Alternatively, create a condition to match just the URIs that you want to rewrite, and redirect the rest.
RE: rewrite with redirect issue - Added by skinniepuppie over 5 years ago
I want everything to redirect to https, just want it to rewrite exactly how it is with http (which is working).
/media/ and /code.py/ shouldn't even come up to the user. Thats why I did:
url.rewrite-once = (
"^/favicon.png$" => "/media/favicon.png",
"^/(.*)$" => "/code.py/$1",
)
RE: rewrite with redirect issue - Added by gstrauss over 5 years ago
$HTTP["scheme"] == "http" { ... then redirect to https } else { ...rewrite }
RE: rewrite with redirect issue - Added by skinniepuppie over 5 years ago
I'm trying so hard to figure this out, but I'm still having the same result.
$HTTP["scheme"] == "http" {
url.redirect = (
"^/favicon.png$" => "https://hostname/favicon.png",
"^/media/(.*)" => "https://hostname/media/$1",
"^/(.*)" => "https://hostname/$1"
)
} else {
url.rewrite-once = (
"^/favicon.png$" => "/media/favicon.png",
"^/media/(.*)" => "/media/$1",
"^/(.*)" => "/code.py/$1",
)
}
RE: rewrite with redirect issue - Added by skinniepuppie over 5 years ago
My mistake, sorry for wasting your time.
I forgot I still had url.rewrite-once within my fastcgi.conf, it must be being called first.
Issue solved, everything works with the example above.
RE: [Solved] rewrite with redirect issue - Added by skinniepuppie over 5 years ago
For anyone attempting to do this, within url.redirect
"^/(.*)" => "https://hostname/$1"
works quite well by itself.
RE: [Solved] rewrite with redirect issue - Added by gstrauss over 5 years ago
$HTTP["scheme"] == "http" { url.redirect = ( "" => "https://${uri.authority}${uri.path}${qsa}" ) } else { url.rewrite-once = ( "^/media/" => "", "^/favicon.png$" => "/media/favicon.png", "" => "/code.py${uri.path}${qsa}", ) }
RE: [Solved] rewrite with redirect issue - Added by skinniepuppie over 5 years ago
Oh neat, thx for that, I was trying to do "https://%0$0" but it wasn't working for me.
RE: [Solved] rewrite with redirect issue - Added by skinniepuppie over 5 years ago
I'm having a slight issue with using both the redirect and rewrite in that example, but when I use one or the other it works fine.
Maybe it's just chrome bugging out on me, but I have been clearing the cache in chrome://net-internals each time I restart lighttpd.