I would like to allow users to only be able to visit index.php
(and also just /
) on my server, and nothing else (returning a 403 if valid and a 404 if an invalid file).
How Can I do this? I've tried the following solutions
Denying access to all files except index.html apache
Denying access to all files except index.php but allow access through "/" in htaccess file
but they don't seem to have any effect.
My .htaccess file is this, but it is having no effect and I can still access other files on my server:
Order allow,deny
Deny from all
<FilesMatch index\.php>
Allow from all
</FilesMatch>
I'm not sure if I need to define anything in my virtualhosts config as well?
My virtualhosts file is:
ServerAdmin webmaster@localhost
ServerName server.mydomain.com
ServerAlias server.mydomain.com
DocumentRoot /var/www/server.mydomain.com
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/server.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/server.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
apache2ctl -S output is:
VirtualHost configuration:
*:443 server.mydomain.com (/etc/apache2/sites-enabled/server.mydomain.com-le-ssl.conf:2)
*:80 server.mydomain.com (/etc/apache2/sites-enabled/server.mydomain.com.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33