Within the “lp” directory on my Apache server, I have multiple HTML files such as “nashik.html”, “hyderabad.html”, etc., alongside corresponding directories named “nashik”, “hyderabad”, etc. Inside each of these directories, there are additional HTML files (e.g., “places.html” inside “nashik” directory). I want to configure my .htaccess file so that when I access URLs like “/lp/nashik”, it serves the corresponding “nashik.html” file without requiring a trailing slash in the URL. However, my current .htaccess rules haven’t successfully handled this for nested directories.
folder structure
lp
├── nashik.html
├── nashik
│ └── places.html
├── hyderabad.html
└── hyderabad
└── places.html
etc...
I’m looking for guidance on crafting Apache .htaccess rules to serve HTML files without trailing slashes in URLs for nested directories. Specifically, I need assistance in configuring the .htaccess file to achieve this behavior for multiple directories and their nested HTML files.
current .htaccess file
RewriteEngine On
RewriteBase /lp/
# Serve city.html if the request is for /lp/city/ or /lp/city
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.html [L]
# Serve files inside city directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ $1/$2.html [L]