Nick M.
Nick M.

Reputation: 155

nginx rewrite rule with try_files

At the bottom of this post is my current nginx rewrite rule and for the most part it is working as it should. The only issue I seem to be coming across is in the example of a link such as example.com/?action=cmd, this action is being processed as example.com/clientarea/?action=cmd

I am looking for a way that when the ? symbol is called that it will automatically append it to example.com/index.php instead of /clientarea/

location = / {
    rewrite ^ /clientarea/ permanent;
}

location ~ ^(.*)$ {
try_files $uri $uri/ /index.php?$1;
}

Upvotes: 2

Views: 6110

Answers (1)

Dayo
Dayo

Reputation: 12775

Assuming you have a recent version of Nignx 1.0.x+ (I think), this should work:

location = / {
    if ($is_args = '?') {
        return 301 $scheme://$host/index.php$is_args$args;
    }
    rewrite ^ /clientarea/ permanent;
}

location ~ ^(.*)$ {
    try_files $uri $uri/ /index.php?$1;
}

Upvotes: 1

Related Questions