如何在PHP CGI上检查mod_rewrite [英] How to check for mod_rewrite on PHP CGI
问题描述
我在共享主机上,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
}
它正在询问apache的路径,我没有此信息,SHELL无法回复我,$ _ SERVER没有任何信息.
4)我已经在.htaccess中使用RewriteEngine On
进行了检查,此后我的网站抛出了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>
a.第一行告诉apache仅在mod_rewrite可用时执行以下代码,
b.第二行启用重写引擎,
C.第三行设置重写来自DOCUMENT_ROOT
的基本目录路径 d.第四行将mod_rewrite_test.txt
文件的内容返回到发送到mod_rewrite_test
目录的任何请求. -
在同一目录中创建一个名为
mod_rewrite_test.txt
的文件.在该文件中写入ok
并保存. -
现在,在您的php脚本中使用
CURL
,调用类似于以下网址,http://www.your-domain.com/mod_rewrite_test/test.php 并检查响应.
因此,根据我们的
.htaccess
代码,如果mod_rewrite处于活动状态并且可以在服务器上运行, 即使test.php文件不存在,它也会返回mod_rewrite_test.txt
文件的内容,即ok
.否则,它将返回404-找不到页面错误.
I am on shared host and PHP is inatalled as CGI script and that is all the problem i am not able to find whether mod_rewrite if enable or not
Note: I don't have any root level access so i can't much do with Shell.
I have tried the following :
1) checked in phpinfo() where i came to know about that this is the wrong place to look for in PHP-CGI.
2) I have tried getting it from apache_get_modules which agi does not work in PHP-CGI :(
3) I have tried :
if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) {
// mod_rewrite is enabled
}
which is asking for path to apache and i dont have this info SHELL cant reply to me and $_SERVER has nothing.
4) I have checked with RewriteEngine On
in .htaccess and after this my site is throwing 500 Internal server error may be because of RewriteEngine is not there, but i need this is written to show someone.
Any body has any idea how to check get this DONE.
Thanks
With PHP CGI there is no easy way to find out whether mod_rewrite is available or not on the server.
So, you need to find out it by making a test call to the server. You can use the following steps for this method,
Create a directory named
mod_rewrite_test
on the server.Add
.htaccess
file in this directory with the following code,<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /mod_rewrite_test RewriteRule .* mod_rewrite_test.txt </IfModule>
a. first line tells apache to execute the below code only if mod_rewrite is available,
b. second line enables rewrite engine,
c. third line sets rewrite base directory path which is fromDOCUMENT_ROOT
d. forth line returns the content ofmod_rewrite_test.txt
file to any request sent tomod_rewrite_test
directory.Create a file named
mod_rewrite_test.txt
in the same directory. Writeok
in this file and save it.Now, using
CURL
in your php script, call the URL similar to,http://www.your-domain.com/mod_rewrite_test/test.php and check the response.
So, as per our
.htaccess
code, if mod_rewrite is active and working on the server, it will return the content ofmod_rewrite_test.txt
file i.e.ok
even though the test.php file does not exists.Otherwise, it will return 404 - Page not found error.
这篇关于如何在PHP CGI上检查mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!