简体   繁体   English

如何在PHP CGI上检查mod_rewrite

[英]How to check for mod_rewrite on PHP CGI

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 我在共享主机上,PHP安装为CGI脚本,这就是所有问题,我无法找到是否启用mod_rewrite

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. 1)在phpinfo()中检查了一下,我才知道这是在PHP-CGI中寻找错误的地方。


2) I have tried getting it from apache_get_modules which agi does not work in PHP-CGI :( 2)我试图从apache_get_modules中获取它,而agi在PHP-CGI中不起作用:(
3) I have tried : 3)我尝试过:

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. 这是问apache的路径,我没有此信息,SHELL无法回复我,$ _ SERVER没有任何信息。
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. 4)我已经在.htaccess中使用RewriteEngine On进行了检查,此后我的网站抛出了500内部服务器错误,可能是因为RewriteEngine不存在,但我需要将此代码写给别人看。

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. 使用PHP CGI,没有简单的方法来找出mod_rewrite在服务器上是否可用。

So, you need to find out it by making a test call to the server. 因此,您需要通过对服务器进行测试调用来找出它。 You can use the following steps for this method, 您可以针对此方法使用以下步骤,

  1. Create a directory named mod_rewrite_test on the server. 在服务器上创建一个名为mod_rewrite_test的目录。

  2. Add .htaccess file in this directory with the following code, 使用以下代码在此目录中添加.htaccess文件,

    <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, 第一行告诉apache仅在mod_rewrite可用时执行以下代码,
    b. b。 second line enables rewrite engine, 第二行启用重写引擎,
    c. C。 third line sets rewrite base directory path which is from DOCUMENT_ROOT 第三行设置了重写基础目录路径,该路径来自DOCUMENT_ROOT
    d. d。 forth line returns the content of mod_rewrite_test.txt file to any request sent to mod_rewrite_test directory. 第四行将mod_rewrite_test.txt文件的内容返回到发送到mod_rewrite_test目录的任何请求。

  3. Create a file named mod_rewrite_test.txt in the same directory. 在同一目录中创建一个名为mod_rewrite_test.txt的文件。 Write ok in this file and save it. 在该文件中写入ok并保存。

  4. Now, using CURL in your php script, call the URL similar to, 现在,在您的php脚本中使用CURL ,调用类似于以下内容的URL,

    http://www.your-domain.com/mod_rewrite_test/test.php and check the response. http://www.your-domain.com/mod_rewrite_test/test.php并检查响应。

    So, as per our .htaccess code, if mod_rewrite is active and working on the server, it will return the content of mod_rewrite_test.txt file ie ok even though the test.php file does not exists. 所以,按照我们.htaccess的代码,如果mod_rewrite的是积极和服务器上的工作,它将返回的内容mod_rewrite_test.txt文件即ok即使test.php的文件不存在。

    Otherwise, it will return 404 - Page not found error. 否则,它将返回404-找不到页面错误。

To check if mod_rewrite module is enabaled, create a new php file in your root folder of your server. 要检查是否启用了mod_rewrite模块,请在服务器的根文件夹中创建一个新的php文件。 Enter the following 输入以下内容

echo phpinfo();

And access file in your browser. 并在浏览器中访问文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM