rav*_*oni 4 php apache mod-rewrite
我在共享主机上,PHP 被安装为 CGI 脚本,这就是我无法找到是否启用 mod_rewrite 的所有问题
Note: I don't have any root level access so i can't much do with Shell.
我尝试了以下方法:
1) 检查了phpinfo(),在那里我知道这是在 PHP-CGI 中寻找的错误位置。
2)我尝试从 apache_get_modules 获取它,而 agi 在 PHP-CGI 中不起作用:(
3)我尝试过:
if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) {
// mod_rewrite is enabled
}
Run Code Online (Sandbox Code Playgroud)
这是要求到 apache 的路径,我没有这个信息 SHELL 无法回复我,$_SERVER 什么也没有。
4) 我已经RewriteEngine On
在 .htaccess 中进行了检查,在此之后我的网站抛出 500 内部服务器错误可能是因为 RewriteEngine 不存在,但我需要将其写入以显示某人。
任何机构都知道如何检查完成这项工作。
谢谢
使用 PHP CGI 没有简单的方法来确定 mod_rewrite 在服务器上是否可用。
因此,您需要通过对服务器进行测试调用来找出它。您可以使用以下步骤进行此方法,
mod_rewrite_test
在服务器上创建一个名为的目录。
.htaccess
使用以下代码在此目录中添加文件,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mod_rewrite_test
RewriteRule .* mod_rewrite_test.txt
</IfModule>
一种。第一行告诉 apache 只有当 mod_rewrite 可用时才执行下面的代码,
b。第二行启用重写引擎,
c。第三行设置重写基目录路径,它来自DOCUMENT_ROOT
d。第四行将mod_rewrite_test.txt
文件的内容返回到发送到mod_rewrite_test
目录的任何请求。
mod_rewrite_test.txt
在同一目录中创建一个名为的文件。写入ok
此文件并保存。
现在,CURL
在你的 php 脚本中使用类似的 URL,
http://www.your-domain.com/mod_rewrite_test/test.php 并检查响应。
因此,根据我们的.htaccess
代码,如果 mod_rewrite 处于活动状态并在服务器上工作,即使 test.php 文件不存在,它也会返回mod_rewrite_test.txt
文件 ie的内容ok
。
否则,它将返回 404 - Page not found 错误。
Dev*_*hod -3
要检查 mod_rewrite 模块是否已启用,请在服务器的根文件夹中创建一个新的 php 文件。输入以下内容
echo phpinfo();
Run Code Online (Sandbox Code Playgroud)
并在浏览器中访问文件。