How to redirect to a query

I Need help with if someone enter www.mysite.com it redirect to
www.mysite.com/site.php?site=1
when I try it just loop and adds
www.mysite.com/site.php?site=1site.php?site=1
site.php?site=1

till it fails

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181278,181278#msg-181278

On Tue, Mar 08, 2011 at 09:43:41AM -0500, sjark wrote:

Hi there,

I Need help with if someone enter www.mysite.com it redirect to
www.mysite.com/site.php?site=1

location = / {
rewrite ^ /site.php?site=1? permanent;
}

in the right server{} block should do what you ask for.

It might do what you want if the initial request is for something like
www.mysite.com/?query

Good luck,

f

Francis D. [email protected]

Same problem I get this error in chrome 310
(net::ERR_TOO_MANY_REDIRECTS):

server {
    listen       80 default;
    server_name  www.mysite.com;
    root   /home/www/mysite;
    include standard.conf; #php-fpm settings

    location = / {
      rewrite ^ /?index=site&id=1? permanent;
    }
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181278,181541#msg-181541

On 09.03.2011, at 12:51, sjark wrote:

location = / {
rewrite ^ /?index=site&id=1? permanent;
}
}
[/code]

location = / {
if ($arg_index = “”) {
rewrite ^ /?index=site&id=1 permanent;
}

 fastcgi_pass   ...
 ... etc ...

}

or you may do without redirect at all:

location = / {
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME /path/to/index.php;
fastcgi_param QUERY_STRING index=site&id=1;
… etc …
}


Igor S.
http://sysoev.ru/en/

Thanks that works! one more question

can I do something like this if $host = ‘one.mysite.com’ and $arg_index
= “” then it should go to one.mysite.com/?index=site&id=1 if
two.mysite.com it go to two.mysite.com/?index=site&id=2

Tryed to replayed AND with & or && but it just give me a error
“configuration file /etc/nginx/nginx.conf test failed”
and I am not allowed todo a if inside of a if

location = / {
      if ($host = 'one.mysite.com' AND $arg_index = "") {rewrite ^
?index=site&id=1 permanent;}
      if ($host = 'two.mysite.com' AND $arg_index = "") {rewrite ^
?index=site&id=2 permanent;}
    }

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181278,181550#msg-181550

On Wed, Mar 09, 2011 at 05:50:33AM -0500, sjark wrote:

Hi there,

Thanks that works! one more question

The main docs are at http://sysoev.ru/nginx/ with useful
English-language
content at http://www.nginx.org/en/docs/ and http://wiki.nginx.org/

If you end up guessing the config syntax, could you mention which docs
you read that were unclear? That way, hopefully, they can be fixed –
or the “right” docs made more findable – so that the next person with
the same difficulty will have an easier time. Thanks!

can I do something like this if $host = ‘one.mysite.com’ and $arg_index
= “” then it should go to one.mysite.com/?index=site&id=1 if
two.mysite.com it go to two.mysite.com/?index=site&id=2

In nginx, “different host names” usually means “different server{}
blocks”. That way, you only have one if() condition to worry about,
which reduces it to a problem already solved :slight_smile:

I realise this may be a simplified example, but: if “index” must always
be present and always equal to “site”, then perhaps whatever handles
the request could be told to assume that? This is similar to Igor’s
“don’t redirect; handle it internally” suggestion.

Maybe similar analysis will make your full application configuration be
clear too.

Good luck with it,

f

Francis D. [email protected]

On Wed, Mar 09, 2011 at 04:51:31AM -0500, sjark wrote:

Hi there,

Same problem I get this error in chrome 310
(net::ERR_TOO_MANY_REDIRECTS):

location = / {
  rewrite ^ /?index=site&id=1? permanent;

That’s not the config that was suggested. The “?” immediately after the
“/” makes all the difference.

The original question was about www.mysite.com redirecting to
www.mysite.com/site.php?site=1 (for which the suggested config should
work).

This question is about www.mysite.com redirecting to
www.mysite.com/?index=site&id=1 (for which, as Igor showed, you must
check the “args” of the query string).

And the next question is about one.mysite.com and two.mysite.com each
redirecting to similar urls with different query strings.

I’ll reply to that one separately.

But different problems get different solutions. And if you don’t know
whether the problems are different (and the docs give no hint), then
it’s
good to ask about the problem you care about rather than a simplified
version that is possibly significantly different.

Cheers!

f

Francis D. [email protected]

Got everything working now. Was trying to get everything under one
“server {” insted of split it up. Thanks for helping me out all :slight_smile:

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181278,181561#msg-181561

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs