How to remove the index.php in the url?

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.

Solutions Collecting From Web of "How to remove the index.php in the url?"

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.

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.