0

Currently I'm using

location /login {
                rewrite ^/login/$ /login.php last;
                rewrite ^/login$ /login.php last;
}

to rewrite www.example.com/login and www.example.com/login/. I was wondering if this was also possible in one statement. I tried rewrite ^/login(/)$ /login.php last; but it didn't work.

Also I noticed since I started using rewrites that some of my css paths are broken because I used a relative paths. I will convert all of them to absolute paths but asked myself if there a more implications when using rewrites that I would need to be aware of.

EDIT:

This is how I handle the .php

location ~ \.php$ {
   if (!-f $request_filename) {
      return 404;
   }
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   include fastcgi_params;
   try_files $uri $uri/ /index.php;
}

1 Answer 1

3
location /login {
    rewrite ^/login/?$ /login.php last;
}

In RegEx, a question mark makes the preceding token optional.

3
  • Thanks quanta, I tried your solution but now the login.php will be downloaded when I enter www.example.com/login. Let me edit my post to show how I handle php.. Sep 20, 2011 at 2:31
  • I got it to work by removing the ~ in location to location /login { Sep 20, 2011 at 2:42
  • ~ is only for case sensitive matching. In your case, /login is enough. But I wonder why you put a ~ causes error when parsing php.
    – quanta
    Sep 20, 2011 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .