I have a site running WordPress defined in a virtual host listening at port 80 (www.example.com).
I want to stop people accessing /wp-admin and wp-login.php but to allow access when they look in a different port like www.example.com:8080/wp-admin or www.example.com:8080/wp-login.php
I added some RewriteRules to show a 404 error page when they hit the site at port 80 and created a new virtual host for the same site that listens at port 8080 as follows:
<VirtualHost 192.168.3.20:80>
Options -Indexes +FollowSymlinks
RewriteEngine on
RewriteRule ^/wp-login.php /wp-content/themes/404.html [R=404,NC]
RewriteRule ^/wp-admin$ /wp-content/themes/404.html [R=404,NC]
DocumentRoot /var/www/html/wordpress
ServerName www.example.com
</VirtualHost>
<VirtualHost 192.168.3.20:8080>
DocumentRoot /var/www/html/wordpress
ServerName www.example.com
</VirtualHost>
It works well showing error 404 when accessing /wp-admin and wp-login.php. When accessing through www.example.com:8080/wp-admin or www.example.com:8080/wp-login.php, it shows the login page as expected, but after entering the credentials and pressing enter to continue, it shows me the error 404 page declared for the virtual host at port 80, and that is what I don't want and after a lot of testing I cannot avoid it.
Does anybody have an idea of how to solve it? Maybe I was trying a wrong approach to this?