I'm using IPB forums. I managed to use friendly urls with nginx server conf modifications. However I need to redirect my old forum's URLs to a redirector php file to get current url of a topic (or forum, member etc.). For example: if url is like /forum/index.php?board=23
, I will do a redirection to redirector.php .
This is my current configuration to be able to use friendly URLs on IPB
location /forum {
try_files $uri $uri/ /forum/index.php;
rewrite ^ /forum/index.php? last;
}
When I do insert an if statement inside this location block like the following, I can not retrieve query parameter "board".
location /forum {
if ($arg_board != "") {
rewrite ^ /redirector.php?q=$arg_board break;
}
try_files $uri $uri/ /forum/index.php;
rewrite ^ /forum/index.php? last;
}
What is missing in here?
Can nginx location blocks match a URL query string? Short answer: No.
Permanent redirects such as NGINX 301 Redirect simply makes the browser forget the old address entirely and prevents it from attempting to access that address anymore. These redirects are very useful if your content has been permanently moved to a new location, like when you change domain names or servers.
Your problem relates to the use of break instead of last. From the documentation:
http://wiki.nginx.org/HttpRewriteModule#rewrite
last - completes processing of current rewrite directives and restarts the process (including rewriting) with a search for a match on the URI from all available locations.
break - completes processing of current rewrite directives and non-rewrite processing continues within the current location block only.
Since you do not define a handler for the /redirector within the /forum location block, your if(..) { rewrite } does not do what you want. Make that break a last, so that the rewrite can trigger the appropriate location block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With