Nginx + PHP

Nginx doesn’t use .htaccess files and it doesn’t have mod_rewrite. Thus to properly set up a site to behave like a site that uses mod_rewrite site, this should be added to the config file. Well, this makes WordPress work … so, it works for me.

  location / {
    root   /home/ben/public_html/sitename/public/; #site root
    index  index.php index.html index.htm; #index order
    if (!-e $request_filename) {
       rewrite ^.*$ /index.php  last; # the meat
    }
  }

This uses Ngnix’s dynamic URL rewriting and makes it behave just as you’d expect. Yay! I forgot about this when setting up a site today, caused me a bit of a headache.

Leave a Reply

Your email address will not be published. Required fields are marked *