0

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

I have perfect setup for www.example.com with all rewrite rules.

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

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

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 ?

1 Answer 1

2

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/www.example.com/examp.le;    # This is your 1

  ....

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

  ....

  location ~ \.php$ {                              # PHP processing
    ....
  }

}
2
  • 2
    Eugh, replace the if with a try_files, please.
    – womble
    Jul 17, 2012 at 13:13
  • Yes, like @womble advised, the, if section could be replaced with try_files $uri $uri/ /index.php?q=$uri$args. Jul 18, 2012 at 3:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .