Question

My Apache 2.2 is running on port "8080" I want to call my site url http://www.example.in:8080/abc/xyz.html/index.php (xyz.html is a folder)

as ....

http://www.example.in:8080/abc/xyz.html

Can any one help me with the .htaccess for this..

NOTE:

1) example.in:8080/abc/xyz.html/ is all fine but I want to avoid the "/" at end.

2) I want to avoid DirectorySlash Tried DirectorySlash Off in .htaccess resulted the list of xyz.html folder.

3) Tried DirectorySlash off and Options -indexes RESULTED 403 Forbidden Error

4) Tried with DirectoryIndex index.php RESULT works when "/" is typed but not working without "/" listing the contents ...

Can any one help me with the .htaccess code .. Thanks in advance.

Was it helpful?

Solution 3

This is how I fixed it

Added the bellow code to root folder .htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(abx/xyz.html)/?$ $1/index.php [L,NC]

And added the bellow code to the .htaccess file in side the xyz.html folder

DirectorySlash Off
Directoryindex index.php
Options -indexes

OTHER TIPS

DirectorySlash has an inherent information disclosure security concern when you turn it off. That means if you turn it off (and you do need to), you have to take care of the trailing slash yourself. So something like this:

DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ /$1/ [L]

Note that this is essentially doing the same thing DirectorySlash does, but instead of redirecting the browser, you're internally rewriting the URI to add the trailing slash. This means it's there as far as the webserver is concerned but the browser doesn't see it.

You can then do the checks for index.php:

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ (.*)/index\.php
RewriteRule ^(.*?)/?index.php$ /$1 [L,R=301]

Here is my .htaccess Kept in side the xyz.html folder

DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ /$1/ [L]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ (.*)/index\.php
RewriteRule ^(.*?)/?index.php$ /$1 [L,R=301]

The result is.... it is listing out the Directory Contents.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top