php脚本(函数),检查服务器上是否允许.htaccess [英] php script(function) to check if .htaccess is allowed on server

查看:51
本文介绍了php脚本(函数),检查服务器上是否允许.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我正在寻找一个PHP函数来检查是否可以在服务器上使用.htaccess文件.

as title says I am looking for a PHP function to check if you can use .htaccess file on your server.

我应该测试什么?

选项1: 也许是否已安装 mod_rewrite 模块?

Option 1: Maybe if mod_rewrite module is installed ?

选项2: 检查" httpd.conf "中是否显示" AllowOverride None ".

Option 2: Check out if "AllowOverride None" presented in 'httpd.conf'.

感谢您的建议,代码也将有所帮助;)

Thank you for your suggestions, code will help too ;)

推荐答案

使用您的php脚本创建.htaccess文件,将重定向写入其中的某个文件,然后调用该文件并检查其是否被重定向.应该是检查.htaccess是否有效的最基本方法之一.

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.

未经测试

<?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";
}
?>

这篇关于php脚本(函数),检查服务器上是否允许.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆