Redirect all requests to a folder’s default document to the parent directory instead. This is an important SEO tactic to avoid duplicate content penalties. For example, a request to both /directoryname/ and /directoryname/index.php would return the identical document response. This redirect should be Permanent (301).

To redirect all requests to one or more documents that have been defined as defaults to their parent directory instead, add the following rule to your nginx.conf:

server { 

	# ...

	rewrite ^/(.*)/index(?:\.(php|html))?$ /$1 permanent;

	# ...

}

This would cause all requests to index.php or index.html anywhere in the site’s URL hierarchy to be redirected to the parent directory’s URL. For example, a request to /articles/index.php would be redirected to /articles/.

Change (php|html) to your own website/language’s default document(s). Separate multiple entries with the pipe | symbol.

socialpilot