Forum Moderators: phranque
IndexOptions FancyIndexing
Options All
RewriteEngine on
# Externally redirect client requests contains htm/html extension to extensionless URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*[^.]+\.php?
# externally redirect to extensionless URI
RewriteRule ^(([^/]+/)*[^.]+)\.php?$ http://www.example.com/$1 [R=301,L]
# and if requested extensionless URL-path plus ".htm" does resolve to an existing file
RewriteCond %{REQUEST_FILENAME}.php -f
# then append ".htm" to resolve the actual filename
RewriteRule ^(([^/]+/)*[^/]+)/?$ $1.php [L]
[edited by: jpm5 at 1:37 pm (utc) on Feb 16, 2013]
RewriteRule ^(([^/]+/)*[^/.]+)$ /$1.php [L] [edited by: g1smd at 1:27 pm (utc) on Feb 16, 2013]
IndexOptions FancyIndexing
Options All
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*[^.]+\.php?
RewriteRule ^(([^/]+/)*[^.]+)\.php?$ www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
# then append ".htm" to resolve the actual filename
RewriteRule ^(([^/]+/)*[^/.]+)$ /$1.php [L] [edited by: jpm5 at 1:44 pm (utc) on Feb 16, 2013]
I'm unable to load the file as the server understands I'm trying to access the directory
DirectorySlash Off
IndexOptions FancyIndexing Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.