Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed ispconfig/nginx on ubuntu 12.10 following "perfect server" here:

I need to apply rewrite rules to nginx from a .haccess file with these contents:

RewriteRule ^(.)/(.)-video_(.*).html$ musicvideo.php?vid=$3

RewriteRule ^([^/]*)-video_(.*).html$ watch.php?vid=$2

i used an online converter and got this output:

location / {
rewrite ^/(.*)/(.*)-video_(.*).html$ /musicvideo.php?vid=$3;

rewrite ^/([^/]*)-video_(.*).html$ /watch.php?vid=$2;

Then I put the code in ./sites-available/default under server block and restarted nginx but I am getting error:

duplicate location "/" in /etc/nginx/sites-enabled/default:133
nginx: configuration file /etc/nginx/nginx.conf test failed

and If I put my rewrite rules within the existing Location:

location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
rewrite ^/(.*)/(.*)-video_(.*).html$ /musicvideo.php?vid=$3;

rewrite ^/([^/]*)-video_(.*).html$ /watch.php?vid=$2;

then nothing happens! could someone please point out to me what I am doing wrong?

share|improve this question

The order of directives matters in nginx. Try moving the rewrite rules up to the top of the / location.

share|improve this answer

Your Answer


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.