-2

I do have a website, which is not Wordpress, and I'm trying a solution for a simple rule.

On NginX how can I write a try_files to this case:

The link is: http://mywebsite.com/index.php?open=fiction

and I need NginX to convert and open this link: http://mywebsite.com/fiction

I need to redirect many links the same way..

Thanks any help.

  • Please tell us what you have already tried, including searching this site or the Web, and what did not work for you. – Deer Hunter Apr 17 '15 at 18:39

2 Answers2

1

Nginx takes care of parameter behind the query string and store them in $args_ParameterName. So just use the location block like so:

 location = /index.php {
    rewrite ^ /$arg_open permanent;
}
location /fiction {
   ...
}
location /secondLink {
   ...
}

so on and so forth.

skip87
  • 195
  • 2
  • 9
0

You could add the following in your location:

try_files $uri $uri/ index.php?open=$uri

You still need to make sure that PHP files are passed to the fcgi process (or whatever you're using as PHP processor).

Gert
  • 198
  • 3
  • 12
  • This is what I use on Wordpress, but in this case is a simple site to use friendly URL and it's not working. I think I did explain wrong, basically what I need is to make the URL prety. The code will always be http://mywebsite.com/index.php?open=fiction, but with pretty URLs, clicking on /fiction should open the index.php?open=fiction and still showing /fiction on URL bar. Sorry for the mess, is not a redirect thing. And I'm using PHP FPM. – Luis FatorXb2 Apr 17 '15 at 20:23
  • @LuisFatorXb2 this doesn't perform a redirect. The browser will keep displaying `$uri` (in your case `/fiction`) – Gert Apr 18 '15 at 11:58
  • Hi Gert, thanks for your help. Actually I have found the code to fix it after your suggestion. You did help because with what you said I was able to search with the correct terms. Thanks and if I could upvote you I would. Here is the correct code: Once again thank you. And to the guy who downvote my question I hope he never need to learn anything else that he already knows, and if he does I hope people send him back to Google to find the answer. – Luis FatorXb2 Apr 18 '15 at 15:24