WordPress Development Stack Exchange is a question and answer site for WordPress developers and 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 have installed wordpress in a subdirectory (blog). In the root directory I have installed Magento. Now the file directory is as following:


My server is nginx. When I set the URL in the wordpress Permalink Settings to:


… all the posts are available. Now I want to remove the index.php from that URL. How should I do that? When I set the custom structure to …


… the URLs are not resolved by WordPress and I get a 404.

share|improve this question
What does your .htaccess look like? See serverfault.com/questions/206491/… – Dustin Jan 16 '13 at 6:11
I suggest searching this site for nginx pretty permalinks, this has been asked and answered before. – Milo Jan 16 '13 at 6:19

Place this code in your functions.php file

   add_filter( 'got_rewrite', '__return_true', 999 );


got_mod_rewrite() function checks whether the current server is apache or not using apache_mod_loaded() function. Since we are using nginx it returns false. So wordpress adds index.php in the url.

By using got_rewrite filter we are telling wordpress that we got rewrite in our server.

share|improve this answer
i put the code in functions.php. all the post still can't available. – stack2013110 Jan 17 '13 at 1:10
Try resetting your permalink in the permalinks section. First change it to default settings, then switch back – Giri Jan 17 '13 at 8:34

The problem likely has to do with the server settings in Nginx for your blog. It's likely that the location rules for /blog/ are wrong, specifically try_files. It should look like this:

location /blog/ {
     try_files $uri $uri/ /index.php$is_args$args;

This tells Nginx the order in which it should try to find the requested resource. It will first start by trying to find the exact object in the URL. If that doesn't exist, it'll try to find that object as a directory. If that doesn't exist, it'll pass the request to index.php along with any arguments or query strings, if present. Since index.php in the main handler for WordPress, this will trigger WordPress to find the page or post you've requested based on your rewrite rules.

The beautiful thing about this configuration is that you can now change your permalink structure to anything WordPress supports without having to change your Nginx rules. This is also the recommended method over using explicit rewrite rules in Nginx.

share|improve this answer
You'll also want to make sure 'index index.php' is added inside the location rules. – Christiaan Apr 18 '13 at 18:34
Awesome, I didn't have idea this actually existed. Just tried it and it's WAY more useful, since I just only have to remember to write it once (and it works for every wordpress site I have in the vps). – pablox May 11 '13 at 3:09
Yup. It's a much more elegant solution than writing if statements, and more reliable. – Christiaan May 31 '13 at 14:08

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.