Home > OS >  .httacces custom redirectioning
.httacces custom redirectioning

Time:02-11

I want to redirect all invalid traffic to my index page. Invalid traffic in this context means:

-Case 1. Nonexistent directories

-Case 2. Nonexistent files

-Case 3. Existing route but only directory: Like in example "validroute/images" or "validroute/images/"

Actually my working code is

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [R,L,QSA]

Options -Indexes

For cases 1 and 2 the conditions and the RewriteRule are redirecting correctly to my index.php For the third case Im using the "Options -indexes" which avoids user to browse my directory and displays the forbidden error. I want to redirect this last case also to the index.php instead.

The nearest approach i got based on redirect 403 error using .htaccess was this

ErrorDocument 403 /index.php

Instead of redirecting ALL forbidden (403) when trying to display a valid "folder" (and ONLY in this case) i seek to redirect to index.

By setting the same redirects i expect the user not to be able to see my directories even if he tries to manually input different routes to see if the directory exists or not. Actually he has the hint because some are "forbidden" and others redirects to index.

This is NOT a duplicate of these because given answers didn't fit me or the issues are not what I intend:

.htaccess redirect - Options -Indexes

.htaccess option -indexes redirect?

.htaccess to redirect everything to index.php, but keep a copy of the website in a subdirectory

Maybe is not possible at all or maybe there is another command or maybe a proper regex combined to RewriteRule to fix the selection.

CodePudding user response:

There is a layer above for the server at which i am not able to access or to see in any way, but as i was handling other kind of permissions (folder accesses by password) i noticed that this had its own way of working without allowing developer to modify this. So i guess there is no way to override such from a higher lvl .htaccess without direct access to server. I was using Plesk Obsidian.

So if you dont have full control on the server your configurations might generate some conflicts.

  • Related