Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is there anyway to direct a visitor using htaccess or anything else from directories like this

http://domain.com/afolder/bfolder/index.php to http://domain.com/afolder/bfolder/

i want it like that when visitor goes to first directory he must be redirected to second one. the point is to hide this part "index.php"


What I have tried:

i have tried this on htaccess file for testing only but it goes wrong

Redirect 302 /afolder/bfolder/index.php /afolder/bfolder/
Posted
Updated 15-Feb-17 2:53am

1 solution

At first you have to understand what a web server is doing when requesting a directory instead of a specific page. Most servers will look if the directory contains specific files and will return the first that exists. If there is none of these files, a directory listing might be generated (if enabled) or an error message is returned (directory listings not allowed).

With Apache this is configured with the mod_dir - directoryindex[^] option.

To enable directory listings use the mod_autoindex - Apache HTTP Server Version 2.4[^] option and set Options +Indexes (e.g. in the htaccess file).

The mod_alias - redirect[^] you have tried is not working for files:
Quote:
The old URL-path is a case-sensitive (%-decoded) path beginning with a slash


I don't know what you really want to achieve. But if directory listings are enabled and you want to redirect from index.php to the directory, just do it within that file by adding something like this to the header of the HTML output:
HTML
<meta http-equiv="refresh" content="0; url=/afolder/bfolder/" />

But note that the file index.php must not be listed with the directoryindex option in this case.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900