How to remove the index.php in the url?

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.

Leave a Comment