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 need to turn my previous site running wordpress into a single page site. My site can only contain a landing page and I want all of the old URL's to 301 redirect to the root of my site.

I have this working, but not exactly how I'd prefer. Currently, everything is redirecting to, but I want it directed directly to

Here's the redirect code I'm using in my location / {} tags:

try_files $uri $uri/ /index.php?q=$uri&$args;
            if ( $uri !~ ^/(index\.php|css|images|uploads|js|robots\.txt|favicon\.ico|wp-admin|launch|wp-login\.php|inc) ) {
                    rewrite ^ permanent;

That bit of code redirects everything except those specific directories and and files that I have listed. This way, I can still access my wp-admin directory to add content to Wordpress, so when I do pull the switch later, I can switch the site back on and have all of the content updated and ready for launch.

If I remove the index.html from my redirect above, my site goes into a redirect loop. If I make the rewrite rule just point to /, then my site also goes into a redirect loop.

Can someone help me update that code so that index.html doesn't show int he browser window as the actual URL? I'd really like the actual URL to be, not


What I really need, is to specify the root directory in my !~ statement. But if I add |/| it allows all files and subdirectories to be ignored... which means my redirect rule never gets called.

Can I specify only a root directory, and not include any of the files or subdirectories within that root directory? This way I can tell nginx not to redirect at / of my domain, but if it finds /index.html it will redirect to /.

share|improve this question
Since it's WordPress, you're probably better served by using a WordPress plugin, such as Ultimate Coming Soon Page. – Michael Hampton Jan 12 '13 at 1:14
@MichaelHampton Thanks for the reply. I'm really against Wordpress Plugins... as the more you use the more problems can crop up in the future. We're running Nginx and Varnish and for performance reasons I'd like to handle this on the server side of things. Besides, I've already spent the time creating the landing page and MailChimp API integration :). I just nee to figure out this last little step (converting /index.html to /) and then everything will be working properly. – Kris Anderson Jan 12 '13 at 3:55
up vote 1 down vote accepted

I see two ways:

  • add |$ to regexp
  • set up a location = / and make it run /index.php on whatever PHP backend you use (probably by setting fastcgi_param SCRIPT_FILENAME .../index.php;
share|improve this answer
Thanks! |$ solved teh issue for me. – Kris Anderson Jan 14 '13 at 23:19

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.