I have a big problem with nginx and it’s wordpress-rules for redirecting/permalinks.
So here is what we have:
- A blog using permalinks (/%category%/%postname%/)
- nginx
- A custom plugin (product comparision) which was coded on a dev-system
Under normal circumstances we just need to use the following nginx-line:
try_files $uri $uri/ /index.php?$args;
But it does not work with the new plugin! I mean I can access all categorys, posts and so on.
Now when the plugin is used there is another section (page) where users can compare different products. The problem is, that this plugin uses the following linkstructure:
/compare/product-name/123
123 is the product-ID.
On the dev-system we did just this:
rewrite ^/compare/([a-z0-9-]+)/([0-9]+)?$ /?page_id=32134&id=$2 break;
This worked just fine (on the dev-system where the permalink feature wasnt active).
After activating the permalink stuff and adding
rewrite ^/compare/([a-z0-9-]+)/([0-9]+)?$ /?page_id=PAGEIDOFLIVESYSTEM&id=$2 break;
location / {
try_files $uri $uri/ /index.php?$args;
}
to my nginx conf, wordpress says that it could not find an article.
I think there is a conflict with the rewrite rules, but I have no idea how to solve it after trying different stuff.
Maybe someone has a good idea!
Regards & excuse my bad english!
Bye
I never understood the
try_files
that uses?args
, I always use$request_uri
instead, you should try itThank you for the answer!
I found a solution by myself a day ago.
The problem was the plugin, which uses own rules but does not register them on wordpress. I used a plugin which allows me to add new rules and put them “on position one”/make them more important than others.
Second issue was an unknown $_GET-Var, which needed to be registered on wordpress. Monkeyman Rewrite Plugin helped me find that out!
After doing both things, I just needed to add
rewrite ^/compare/([a-z0-9-]+)/([0-9]+)?$ /compare-site-name?id=$2 break;
to my nginx-conf!
Thats the magic…
Maybe I can help someone with this solution on some (I think) bad written plugins!
Bye