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 could use a little help with rewrite and nginx... Basically the structure of my App looks like this

Headdirectory --
           -APPBase
           -SomeMoreStuff
           -WWWDirectory
           .htaccess

So i need to redirect into the WWWDirectory when i open the Headdirectory. In Apache its done with a htaccess and the following Content :

RewriteEngine On
RewriteRule ^(.*) www/$1

I already tried in Nginx :

location /Headdirectory {    
rewrite ^/(.*) /www/$1;
      }

And i tried to create an Alias but that didnt work...

Would be nice if someone could help me out.

Have a nice Day

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Here is how it could be done in Nginx...

server {
  server_name domain.com;
  root /path/to/domain.com;
  index index.php; # or index.html or something that suits the application

  location ~ /Headdirectory/WWWDirectory/ {
    # do some stuff with WWWDirectory
    # something like try_files $uri =404;
  }

  location ~ /Headdirectory/ {
    rewrite ^/Headdirectory/(.*)$ /Headdirectory/WWWDirectory/$1 permanent;
  }

  # other blocks and directives

  location / {
    # do stuff with the root
    # such as try_files $uri =404;
  }
}

Questions?

share|improve this answer
    
That worked , Thank you very much. I'm still pretty new to this regular expression stuff :) –  Robin Jun 21 '12 at 13:05
    
You're welcome @Robin. –  Pothi Jun 21 '12 at 15:28
add comment

It is a little bit confusing question...

Your configuration is, that if someone will try http://some.host/Headdirectory, it will be rewriten to http://some.host/www/Headdirectory, which is not you want, I pretend...

Try this:

root /full/path/to/the/Headdirectory
location / {
     rewrite ^/(.*) /www/$1;
}

EDIT:

I'm sorry, you will need this config block:

location /www {
}

It will stop rewriting...

share|improve this answer
    
Thank you in Advance. Sorry , its a bit early for me. I need to open the Headdirectory , because my App requires it, but the redirect needs to go to the www directory. When i try this i get in a redirect loop. www/www/www/www/www/www Basically if someone goes to the –  Robin Jun 21 '12 at 9:39
    
Please, try add a new block to the config... –  Jan Marek Jun 21 '12 at 9:50
    
Sorry, this block existed with the old path ..^^ Now Firefox and Chrome say that there are too many redirects. Errorlog is empty. Thanks , i only want to migrate to nginx :/ –  Robin Jun 21 '12 at 10:03
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.