I am struggling with some Nginx rewrits for url arguments passed to index.php:
- Old:
?topic=10126.msg36887
- New:
?posts/36887/
My two questions:
1) How do I rewrite to the new argument structure since it uses "parameter/value/" rather than the traditional "parameter=value" structure?
2) My "if" statement isn't triggering, and I can't figure out why...
The test url domain.com/forum/index.php?topic=10126.msg36887
should redirect to /success
, but it isn't rewritten at all.
Here's my current Nginx config:
location /forum/ {
index index.php index.html index.htm;
try_files $uri $uri/ /forum/index.php?$uri&$args;
location /forum/index.php {
# I know Nginx 'If is Evil', but it's the only way
# to trigger rewrites on url parameters
if ($arg_topic ~ [0-9]+\.\bmsg([0-9]+) {
# testing whether 'if' triggers:
rewrite ^ /success? redirect;
# full rewrite:
# rewrite ^\/forum\/index\.php ^\/forum\/index\.php\?posts\/$1\/? redirect;
}
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}