Enabling PATH_​INFO

There are some cases where Craft will generate URLs to your site that include “index.php”, followed by the Craft path:

  • All URLs, if your omitScriptNameInUrls config setting is set to false, or 'auto' and Craft’s test determined that the result should be false.
  • URLs generated using UrlHelper::getActionUrl() or the template function actionUrl(), preventing any POST parameters that might accompany the request from getting lost in an index.php redirect.
  • URLs generated using using UrlHelper::getUrl() or the template function url() where the fourth argument passed is true.

When it is determined that a URL should include “index.php”, Craft must then decide how to append the Craft path onto the URL after “index.php”. There are two options:

  1. Append it as a query string (e.g. http://example.com/index.php?p=some/path)
  2. Treat “index.php” as just another directory segment (e.g. http://example.com/index.php/some/path)

The second option is generally preferable because it is cleaner and more semantic, in that it does a better job expressing that “some/path” is the page you’re linking to, and not just some additional parameter on the request that will affect the response in some not-so-meaningful way.

When a request using the second format comes in, behind the scenes the request will get routed to index.php, and whatever follows it will get stored in a server environment variable called “PATH_INFO”, which Craft has access to and will use in its own internal routing.

The problem is, not all servers are equipped to support PATH_INFO, and will simply try to find a directory called “index.php”. (That’s why the actual URL format Craft will use is determined by a config setting.)

You can test whether your server supports PATH_INFO by pointing your browser to https://example.com/index.php/testPathInfo. If “success” is returned, you’re golden. Otherwise you’ve got a little work to do if you want Craft to use PATH_INFO-formatted URLs.

If you’re running Apache, you should just need to set the AcceptPathInfo directive in your .htaccess file:

AcceptPathInfo On

If you’re running Nginx, it’s a little more complicated, since Nginx does not have any built-in concept of PATH_INFO. It can be done by following these instructions, though.

If you’re running IIS, you’ll want to configure it so that it’s using FastCGI to host PHP applications. Once you’ve done that, setting the cgi.fix_pathinfo setting to 1 as described in that article will enable proper PATH_INFO support in IIS.

Applies to Craft CMS 3.