I am using this function to get content of .htaccess file
file_get_contents('http://www.example.com/.htaccess')
But its give me this error
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
But When i open this url its working fine
file_get_contents('http://www.example.com/robots.txt')
Please help me to solved this Problem.
Thanks
The default configuration for any HTTP server that supports .htaccess
configuration files is to not expose them over HTTP.
At best, the details of the server's configuration are not something the public needs to know about and, at worst, could be a serious security problem if exposed to the public.
You could look in to reconfiguring the server to make the .htaccess
files public, but you would be better served accessing the file using the file system instead of HTTP.
You cannot get content through web, but you can access it with simple service;
htaccess.php
<?php
$password = $_GET["pass"]; // password protection
if(!empty($password) && $password == "your_password") {
$file = 'path/to/.htaccess'; //physical path on server
if (file_exists($file)) {
echo file_get_contents( $file );
}
}
And go to
http://your_domain.com/htaccess.php?pass=your_password
I just want to extend Quentin's answer:
.htaccess
is a file by your server to tell the system how to handle HTTP requests such ass file and folder access. It is ill recommended to have that exposed to an outside requester unless in 2 condition:
1) within a CMS file manager in this case it should display it to you so that you can edit the file (like cpanel or directadmin)
2) FTP.
calling it externally...no.