Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check AllowOverride value using PHP?

Is there anyway to use PHP to check the value of AllowOverride too see if .htaccess will have any effect?

like image 713
ndmweb Avatar asked Aug 21 '11 07:08

ndmweb


1 Answers

I am not aware of a clean, direct way to do this.

If you have http access to the folder you want to check this for, you could write something into the .htaccess file that will trigger a certain kind of output.

For example, you could set a header (this has an added dependency on mod_headers, though):

<FilesMatch "\.(php)$">
<IfModule mod_headers.c>
Header set htaccess_works "yes"
</IfModule>
</FilesMatch>

then make a request from PHP, and check the response headers, e.g. using curl's CURLOPT_HEADER. If they contain the htaccess_works header, it works.

Another method that is terrible but guaranteed to work independently from specific Apache modules is to programmatically write gibberish into the .htaccess file, then to make a curl request like above, and to check for a 500 status code. If it throws a 500, the .htaccess file got interpreted. But as said, this is terrible - if possible, go with the headers method instead.

like image 75
Pekka Avatar answered Sep 17 '22 11:09

Pekka