My main question is, for security reasons, I’d like to know if it’s possible to virtually change the name (in a sense) of a website file using .htaccess. For instance, if I have a file /index.php and I want to make it such that calls for /mysite are redirected to /index.php, but I also want calls to /index.php to return as either an error 403 or 404. Is this possible? And if so, how could it be done?
Also, I’ve been searching for a full documentation on the .htaccess directive syntax, but I couldn’t find anything. My second question is, Does anyone know of a good generic reference of all the directives and their syntax? (I couldn’t even find one in w3schools)
First I’ll start by saying w3schools doesn’t have particularly good references for anything. The Apache mod_rewrite documentation is really good, and I always go there first.
The first part of your request is pretty straightforward as a rewrite. But before we get there, let’s start by preventing direct requests to
index.php. In order to do this without messing up our other rules we will use the%{THE_REQUEST}variable to matchindex.phpand forbid access.We need the first part using
THE_REQUESTto avoid causing conflicts with the second part rewriting into index.php.If you want to serve a 404 to make it look like
index.phpdoesn’t even exist, replace the[F]with[R=404,L]