Beny Hirmansyah
Beny Hirmansyah

Reputation: 13

Nginx rewrite rules with try_files

I need help to converting this .htaccess to Nginx. Here is the .htaccess code:

RewriteRule wp-content/thesis/skins/(.*)/css.css wp-admin/admin-post.php?action=thesis_do_css

I already convert those rules to online nginx converter. So far I get this code:

 rewrite /wp-content/thesis/skins/(.*)/css.css /wp-admin/admin-post.php?action=thesis_do_css;

I put those code above under try_files rules. Here is the complete code:

 location / {
  try_files $uri $uri/ /index.php?q=$uri$is_args&$args;
  rewrite /wp-content/thesis/skins/(.*)/css.css /wp-admin/admin-post.php?action=thesis_do_css;
  }

So, it doesn't work. Please help me understanding about nginx rules. Thanks.

Beny

Upvotes: 0

Views: 940

Answers (2)

user1600649
user1600649

Reputation:

try_files is final. You cannot put anything after it and expect it to be evaluated. Think of try files as an if-then-else statement, where the last part is always the else. Since there are probably a lot more rules involved, you are best off consulting the WordPress codex.

Upvotes: 1

Kevin Worthington
Kevin Worthington

Reputation: 457

If you need just to rewrite that one css.css file to wp-admin/admin-post.php?action=thesis_do_css then try this:

    if ($request_filename ~ wp-content/thesis/skins/classic-r/css.css ) {
            rewrite ^ http://mydomain.com/wp-admin/admin-post.php?action=thesis_do_css? permanent;
    }

That should be within your server{ block. Make sure to change mydomain.com to your actual domain, of course.

I hope that helps.

Upvotes: 0

Related Questions