I try to create a very simple rewrite rule with nginx, but i doesnt
work.
I have set up my server with a “catch all” server_name *.mydomain.com
I then try to create a rewrite rule so that requests to
mysubdomain.mydomain.com/wiki.php?wiki=WIKIPAGE will be rewritten to
mysubdomain.mydomain.com/WIKIPAGE
Here is the option that i thought would work:
server {
server_name mysubdomain.domain.com;
if (!-e $request_filename) {
rewrite ^/(.*)$ /wiki.php?wiki=$1 last;
}
}
Suggestions to why this does not work are highly appreciated.
Thanks,
per
I think the first problem is that you’re redirecting to wiki.php instead
of
to the “/WIKIPAGE” url. As I found out last week, replacing query
strings in
nginx can be tricky. Does this work? (it won’t work with more query
string
params)
server {
if ($query_string ~ ^wiki=(.)$) {
rewrite ^(.)$ /$1 break;
}
}
-tieg
On Sun, Mar 9, 2008 at 8:24 PM, Tieg Z. [email protected]
wrote:
Hi, thanks for your response. I tried your proposed config change, but
it
still does not work. And there’s only one query string.
Per
Did you do a full “reload” of the nginx conf? Or just restart? Also,
what’s
the resulting url that it takes you too?
On Sun, Mar 09, 2008 at 08:01:44PM +0100, Per Hans Hansen wrote:
server {
server_name mysubdomain.domain.com;
if (!-e $request_filename) {
rewrite ^/(.*)$ /wiki.php?wiki=$1 last;
}
}
Suggestions to why this does not work are highly appreciated.
I do not understand.
You said, you want to rewrite
/wiki.php?wiki=WIKIPAGE => /WIKIPAGE
but your rewrite do opposite thing:
/WIKIPAGE => /wiki.php?wiki=WIKIPAGE
What exactly do you want ?
I didnt do a full reload, but i’ve tried now and it still doesn’t work.
I’m
taken to the URL that i want to (/WIKIPAGE) but i’m getting a 404.
Oh, I thought it was the opposite; that’s probably why mine doesn’t
work,
-tieg
On Mon, Mar 10, 2008 at 10:07 AM, Igor S. [email protected] wrote:
What exactly do you want ?
What i meant was that when i visit sub.domain.com/WIKIPAGE the page
wiki.php?wiki=WIKIPAGE
shall be shown. I guess i mixed up in the original post. Sorry for that.
Per