php script(function) to check if .htaccess is allowed on server
.htaccess, mod-rewrite, php
Solution
Create a .htaccess file with your php script, write a redirect into it for some file, and then call the file and check if it's redirected. Should be one of the most basic ways to check if .htaccess works.
Edit: Not tested
<?php
$html1 = "test.html";
$html2 = "test2.html";
$htaccess = ".htaccess";
$string1 = "<html><head><title>Hello</title></head><body>Hello World</body></html>";
$string2 = "<html><head><title>Hello</title></head><body>You have been redirected</body></html>";
$string3 = "redirect 301 /test.html /test2.html";
$handle1 = fopen($html1, "w");
$handle2 = fopen($html2, "w");
$handle3 = fopen($htaccess, "w");
fwrite($handle1, $string1);
fwrite($handle2, $string2);
fwrite($handle3, $string3);
$http = curl_init($_SERVER['SERVER_NAME'] . "/test.html");
$result = curl_exec($http);
$code = curl_getinfo($http, CURLINFO_HTTP_CODE);
if($code == 301) {
echo ".htaccess works";
} else {
echo ".htaccess doesn't work";
}
?>
Problem
as title says I am looking for a PHP function to check if you can use .htaccess file on your server. What should I test for ? Option 1: Maybe if mod_rewrite module is installed ? Option 2: Check out if "AllowOverride None" presented in 'httpd.conf'. Thank you for your suggestions, code will help too ;)