Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have two domains. I'm using for my normal site and examp.le for the URL shortener.

I have perfect setup for with all rewrite rules.

In my web root for, there's a directory called examp.le.

I wish to redirect all the traffic hitting examp.le to the index.php in /absolute/path/

So my question has basically two sub-questions:

  1. How do I modify the default.conf file so that examp.le maps to the directory in my web root?
  2. How do I pass SOMEURLIDENTIFIER in http://examp.le/SOMEURLIDENTIFIER to http://examp.le/index.php?i=SOMEURLIDENTIFIER ?
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Just create new server instance in nginx config for hostname examp.le. It should look something like this:

server {
  listen 80;
  server_name examp.le;
  root /absolute/path/;    # This is your 1


  location / {
    if (!-e $request_filename) {
      rewrite ^/(.*)$ /index.php?=$1 last;         # This is your 2


  location ~ \.php$ {                              # PHP processing

share|improve this answer
Eugh, replace the if with a try_files, please. – womble Jul 17 '12 at 13:13
Yes, like @womble advised, the, if section could be replaced with try_files $uri $uri/ /index.php?q=$uri$args. – hangover Jul 18 '12 at 3:46

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.