apache_get_modules() solution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zubair1
    New Member
    • Sep 2008
    • 79

    apache_get_modules() solution

    Hello,

    I am using mod_rewrite in one of my scripts, and needed to detect if the mod_rewrite module is loaded.

    I was using apache_get_modu les() before but after switching to a new host, i noticed that its disabled on the server and they won't enable it either.

    But i 100% that mod_rewrite is enabled, but no way to know via my script since it used to rely on that function.

    I was wondering if someone knows of any other ways to detect if mod_rewrite is enabled?

    I would really appreciate any help :)

    Regards,
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    You could always just create a unique rewrite rule that - if mod_rewrite is enabled - would redirect you to somewhere (an empty text file, for example). Then you would just use get_headers() on the URL and see if it returns 200 or 404 as the HTTP response (fist element of the return array).

    Comment

    • zubair1
      New Member
      • Sep 2008
      • 79

      #3
      Thanks for the reply, that's an awesome idea at least for second choice.

      is it possible for you to provide me with some code to get me started?

      Regards,

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Create your rewrite-rule. Something like:

        [code=apache]
        RewriteRule ^/path/to/rewrite$ /rewrite/to
        [/code]

        Then in your PHP script that needs to know whether the rewrite engine is working, call get_headers() on that URL:

        Code:
        $headers = get_headers("http://yoursite/path/to/rewrite");
        
        if ($headers[0] == '404') 
            $rewrite_engine_enabled = false;
        Something like that.

        Comment

        Working...