0

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

3 Answers3

3

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I want to show content of .htaccess file in my API. Is there any way to show content of .htaccess file?. Without login in to server. – user1577168 Apr 03 '14 at 06:07
  • 1
    Your reasons for wanting to access the file don't change anything about this answer. It still holds. – Quentin Apr 03 '14 at 06:09
0

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
Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
0

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.

azngunit81
  • 1,574
  • 2
  • 20
  • 38