php - protect a file using .htaccess -


I have the file to use .htaccess in my site. My site is built on WordPress, and it already has .htaccess file, the file I want to protect is the .htaccess file in the same directory, so that means that I can not create another .htaccess file.

code in existing .htaccess file

  #WordPress & Lt; IfModule mod_rewrite.c & gt; RewriteEngine On RewriteBase / RewriteRule ^ index \ .php $ - [L] Revcranked% {REQUEST_FILENAME}! -f rewrite% {REQUEST_FILENAME}! -D rewriteable /index.php [L] & lt; / IfModule & gt; # END WordPress  

How can I insert the code given in the code above?

  & lt; FilesMatch file.php & gt; AuthName "Restricted File" AuthType Basic AuthUserFile /path/to/the/.htpasswd Legitimate User Required & lt; / FilesMatch & gt;  

I tried to put the comment #END below the WordPress, but when I try to access the file it does not pop up a box. I also have & lt; Files & gt; & Lt; / Files & gt; and call it & lt; IfModule & gt; & Lt; / IfModule & gt; Have tried to put inside and still there is no luck any body can experience in using .htaccess file?

It is possible that the operation does not work because the apache module responsible for it is disabled.

Check that your Apache module is mod_authn_core enabled or not. If the module is not enabled, just enable it:

  sudo a2enmod  
  apache2ctl -m  

Mod_authn_core


Comments