IT박스

PHP에서 mod_rewrite가 활성화되어 있는지 확인하는 방법은 무엇입니까?

itboxs 2020. 6. 13. 19:32
반응형

PHP에서 mod_rewrite가 활성화되어 있는지 확인하는 방법은 무엇입니까?


mod_rewrite에서 Apache AND IIS 에서 활성화 되어 있는지 확인할 수 있는지 궁금합니다 PHP.

IIS 용 ModRewrite 가 존재합니다. 확인하십시오 here.

그래서, PHP 스크립트를 찾고 있어요 그것에 대한 검사 mod_rewrite아파치IIS.

누구든지 그러한 스크립트를 알고 있거나 작성할 수 있습니까?

특히 Microsoft IIS의 경우 .

감사!


mod_php를 사용한다면을 사용할 수 있습니다 apache_get_modules(). 활성화 된 모든 모듈의 배열을 반환하므로 활성화되어 있는지 확인하려면 mod_rewrite간단하게 수행 할 수 있습니다

in_array('mod_rewrite', apache_get_modules());

불행히도 CGI 로이 작업을 수행하려고 시도 할 가능성이 높으므로 조금 더 어려워집니다.

그래도 다음을 사용하여 테스트 할 수 있습니다.

strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false

경우 위의 조건들을 평가는하기 위해 true, 다음 mod_write을 사용할 수 있습니다.


이 코드를 복사하여 실행하십시오.


<?php
 if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
 $res = 'Module Unavailable';
 if(in_array('mod_rewrite',apache_get_modules())) 
 $res = 'Module Available';
?>
<html>
<head>
<title>A mod_rewrite availability check !</title></head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>

나는 Christian Roy의 솔루션을 좋아 합니다 .

###  .htaccess

<IfModule mod_rewrite.c>

    # Tell PHP that the mod_rewrite module is ENABLED.
    SetEnv HTTP_MOD_REWRITE On

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # The rest of your rewrite rules here

</IfModule>

그런 다음 PHP 코드에서 확인할 수 있습니다

    array_key_exists('HTTP_MOD_REWRITE', $_SERVER);

이것이 IIS에서도 작동하는지는 알 수 없지만 (확인할 방법이 없습니다) 확률은 좋습니다.


이 코드와 함께 info.php 파일을 업로드하고 실행하십시오.

<?php 
phpinfo();

페이지에서 mod_rewrite를 검색하고 Loaded Modules에서 찾을 수 있는지 확인하십시오.


당신이 단순히 찾을 수 있도록 너무 어렵게하지 마십시오 phpinfo();

여기에 이미지 설명을 입력하십시오

도움이 되길 바랍니다.

감사


커맨드 라인을 통해 우리는 centOs로 이것을 할 수 있습니다.

httpd -l

<?php
phpinfo();
?>

로드 된 모듈 행의 apache2handler에서 구성을 확인하십시오.

이것은 간단하고 작동합니다.

<?php foreach( apache_get_modules() as $module ) echo "$module<br />";  ?>

이것은 Apache와 IIS 모두에 Mod_rewrite가 활성화되어 있는지 확인하는 현재의 방법입니다.

/**
 * --------------------------------------------------------------
 *  MOD REWRITE CHECK
 * --------------------------------------------------------------
 *                                        - By A H Abid
 * Define Constant for MOD REWRITE
 * 
 * Check if server allows MOD REWRITE. Checks for both 
 * Apache and IIS.
 * 
 */
if( function_exists('apache_get_modules') && in_array('mod_rewrite',apache_get_modules()) )
    $mod_rewrite = TRUE;
elseif( isset($_SERVER['IIS_UrlRewriteModule']) )
    $mod_rewrite = TRUE;
else
    $mod_rewrite = FALSE;
define('MOD_REWRITE', $mod_rewrite);

It works in my local machine and also worked in my IIS based webhost. However, on a particular apache server, it didn't worked for Apache as the apache_get_modules() was disabled but the mod_rewrite was enable in that server.


You can get a list of installed apache modules, and check against that. Perhaps you can check if its installed by searching for its .dll (or linux equivalent) file.


Two lines of code:

$isEnabled = in_array('mod_rewrite', apache_get_modules());
echo ($isEnabled) ? 'Enabled' : 'Not enabled';

One more method through exec().

exec('/usr/bin/httpd -M | find "rewrite_module"',$output);

If mod_rewrite is loaded it will return "rewrite_module" in output.


mod rewrite에 관한 또 다른 아이디어는 mod rewrite와 관련하여 서버가 PHP를 필요로하지 않는 것입니다. 왜냐하면, 가능성이 없다면 테스트 디렉토리를 작성하여 test.php를 다시 작성하여 test.php에 다시 작성하십시오. http를 통해 test.php에 넣은 예상 결과를 얻었는지 확인하십시오.

실제로 더럽습니다.


이 기능을 사용하십시오 :

function apache_module_exists($module)
{
    return in_array($module, apache_get_modules());
}

알려진 파일로 리디렉션 한 다음 해당 리디렉션이 실제로 curl에서 작동하는지 확인하는 방법은 무엇입니까?

참고 URL : https://stackoverflow.com/questions/9021425/how-to-check-if-mod-rewrite-is-enabled-in-php

반응형