user1106340
user1106340

Reputation: 106

Nginx Redirect Loop

Below is my configuration for nginx.

location / {
    try_files $uri $uri/ $uri.html $uri.php?$query_string;

    # Remove trailing slash
    rewrite ^/(.*)/$ /$1 permanent;

    rewrite /authors/(.*) /authors/search.php?author=$1;
}

The problem I am having is that when I go to www.mywebsite.com/authors this causes an infinite redirect. What I want is for www.mywebsite.com/authors to load www.mywebsite/authors/index.php and www.mywebsite.com/authors/EVERYOTHERSTRING to go to the last rewrite. How can I achieve this with rewrites?

Edit: And still have the trailing slashes removed.

Upvotes: 0

Views: 380

Answers (1)

Dayo
Dayo

Reputation: 12805

Try changing these rewrite rules ...

rewrite ^/(.*)/$ /$1 permanent; 
rewrite /authors/(.*) /authors/search.php?author=$1;

to ...

rewrite ^/authors/(.*) /authors/search.php?author=$1 last;
rewrite ^/(.+)/$ /$1 permanent; 

Upvotes: 1

Related Questions