Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
location /login {
    rewrite ^/login/?$ /login.php last;
}

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

share|improve this answer
    
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.. –  Frank Vilea Sep 20 '11 at 2:31
    
I got it to work by removing the ~ in location to location /login { –  Frank Vilea Sep 20 '11 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 '11 at 2:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.