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.

I'm using Nginx and make a small conf file like this :

server {
  listen 80;
  server_name domain.com;
  root /var/www/script;

  location /something {
      root /var/www/another_script/;
      rewrite /something/(.*)$ /index.php?var=$1;
  }
}

the problem appear with the rewrite rule which go back to the /var/www/script instead of /var/www/another_script

Can i rewrite to the new root of the location ? or it's impossible ?

Thanks in advance .

p.s : someone maybe suggest to use alias rather than root , but it's not the real problem.

share|improve this question
    
Is it an alternative to drop the use of the root-parameter in the server-block and explicitly define it in all location-blocks? –  pkhamre Feb 27 '13 at 9:47
    
I try it too :) , Nginx will use the /etc/nginx/html/ as a root –  eyadof Feb 27 '13 at 10:48
    
Which index.php do you want to load? You specified /index.php which is of course located in /var/www/script. Do you want /something/index.php instead, which is located in /var/www/another_script? –  Michael Hampton Feb 28 '13 at 1:30
    
@MichaelHampton yes that what i want –  eyadof Feb 28 '13 at 10:10

1 Answer 1

The root directive does not apply outside of the location it is in.

If you want to rewrite one location into another location and change the root, then you have to specify such root within the latter location.

share|improve this answer
    
thanks for your answer but i don't want to rewrite to another location i want to rewrite inside my location . –  eyadof Mar 3 '13 at 10:52

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.