Vipin Kumar
asked on
Redirect a subdirectory to specific page in root directory using .htaccess
Hi,
I have the below folder structure in my www directory.
www/website/include/client /
The website folder contains all the files that are to be accessed by the users. The include folder contains all the include files.
Currently when someone directly tries to access any file in include or client folder they are able to access them. I placed a .htaccess containing "Deny from All" in the include folder which has stopped users from accessing the files in include and client folder.
But instead of that I want them to be redirected to a file in website folder whenever someone tries to directly access the files in include folder or any subfolder that include contains.
Also, currently I am using this on localhost so kindly let me know such redirect that even later on this website moves to any domain I don;t need to make changes in the .htaccess file.
I hope, I have explained my self here.
Thanks in advance.
I have the below folder structure in my www directory.
www/website/include/client
The website folder contains all the files that are to be accessed by the users. The include folder contains all the include files.
Currently when someone directly tries to access any file in include or client folder they are able to access them. I placed a .htaccess containing "Deny from All" in the include folder which has stopped users from accessing the files in include and client folder.
But instead of that I want them to be redirected to a file in website folder whenever someone tries to directly access the files in include folder or any subfolder that include contains.
Also, currently I am using this on localhost so kindly let me know such redirect that even later on this website moves to any domain I don;t need to make changes in the .htaccess file.
I hope, I have explained my self here.
Thanks in advance.
ASKER
@Lucas,
When I placed your code in the .htaccess file and placed that file in the root directory it is giving me the Internal Server Error
I tried placing the .htaccess file in the include folder as well it is the same.
When I placed your code in the .htaccess file and placed that file in the root directory it is giving me the Internal Server Error
I tried placing the .htaccess file in the include folder as well it is the same.
There may be something else in the htaccess that's conflicting with the code I gave you.
If you put the code I gave you in here, you'll see the logic is sound:
http://htaccess.madewithlove.be/
What else is in your htaccess file? Also, how are you editing the file? Some text editors will insert hidden characters that can cause issues.
If you put the code I gave you in here, you'll see the logic is sound:
http://htaccess.madewithlove.be/
What else is in your htaccess file? Also, how are you editing the file? Some text editors will insert hidden characters that can cause issues.
ASKER
I placed a .htaccess containing "Deny from All" in the include folder which has stopped users from accessing the files in include and client folder. a possible unintended consequence is the website not being able to access the include/client folders
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Steve,
Here are the inputs for questions:
1. Apache Version - 2.4.9
2. Don't know how to get VirtualHost definition, although I have not defined any
3. the DocumentRoot is the /website/
4. C:\program files\wamp\www
There are no Deny directive in .htaccess file. I tried the alternative rules your provided but it is the same case. The Apache access/error logs shows the below. I tried placing the .htaccess in root folder as well the include folder but no difference.
::1 - - [24/Jun/2015:11:20:24 +0530] "GET /schweickert/include/clien t/add-staf f.inc.php HTTP/1.1" 500 616
::1 - - [24/Jun/2015:11:18:45 +0530] "GET /website/include/client/ad d-staff.in c.php HTTP/1.1" 500 616
[Wed Jun 24 11:18:45.862335 2015] [core:alert] [pid 6724:tid 952] [client ::1:4850] C:/wamp/www/website/includ e/.htacces s: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Jun 24 11:20:24.617159 2015] [core:alert] [pid 6724:tid 952] [client ::1:4898] C:/wamp/www/schweickert/.h taccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Kindly let me know if anything else is required.
Here are the inputs for questions:
1. Apache Version - 2.4.9
2. Don't know how to get VirtualHost definition, although I have not defined any
3. the DocumentRoot is the /website/
4. C:\program files\wamp\www
There are no Deny directive in .htaccess file. I tried the alternative rules your provided but it is the same case. The Apache access/error logs shows the below. I tried placing the .htaccess in root folder as well the include folder but no difference.
::1 - - [24/Jun/2015:11:20:24 +0530] "GET /schweickert/include/clien
::1 - - [24/Jun/2015:11:18:45 +0530] "GET /website/include/client/ad
[Wed Jun 24 11:18:45.862335 2015] [core:alert] [pid 6724:tid 952] [client ::1:4850] C:/wamp/www/website/includ
[Wed Jun 24 11:20:24.617159 2015] [core:alert] [pid 6724:tid 952] [client ::1:4898] C:/wamp/www/schweickert/.h
Kindly let me know if anything else is required.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Will try and get back
For example, if there are legitimate reasons for the files to be accessible, you may not want to redirect every person that tries to access a file here.
In any event, you can put this code in the root directory .htaccess file to redirect all references into the include folder and below:
Open in new window