How to customise the directory listing of a folder?

So in folders without directory indexes (ie. index.html), it shows apache’s default directory listing page when accessed. How do I make it display a custom php page without using an actual .php file instead?
Like for example:

# .htaccess
CustomDirectoryListing "(insert php code here)"

What’s wrong with just creating an “index.php” file? It would probably be much simpler.


Looking at this article, it does seem that Apache provides some options to customize the directory index page:

But since the directory index page is generated by Apache, you’re pretty much limited to some styling tweaks. And you can’t use PHP code in there, no Apache config accepts PHP code.

If you do want to have PHP, you’ll need a PHP file. Then you can just drop that file as an index.php file in the directory you’re trying to make accessible, or use .htaccess rules to use a single PHP script for all multiple directories (using rewrite rules or by disabling indexing and setting a custom 403 page).


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.