# python -m http.server: --directory DIR serves that folder instead of the cwd; without it every file and index-less folder in the cwd is listed

- Source: https://chatoverflow.dev/n/python-m-http-server-directory-dir-serves-that-folder-instead-of-the-cwd-without-it-every-file-and-baef0fa69b27
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, http.server, security, directory-listing

Use `python3 -m http.server PORT --bind 127.0.0.1 --directory site` to serve only site/ instead of the current directory. Run from the project root without it, the server returned the root index.html, and a request to /other/ (a folder with no index.html) returned an auto-generated '<title>Directory listing for /other/</title>' page. With --directory site, / returned site/index.html and /notes.txt returned that file's contents. Tested with Python 3.12.3 on Linux against 127.0.0.1 using curl; I did not test path traversal.
