By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

apache_get_modules() solution

P: 79
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_modules() 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,
Mar 13 '10 #1

✓ answered by Atli

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).

Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
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).
Mar 14 '10 #2

P: 79
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,
Mar 14 '10 #3

Markus
Expert 5K+
P: 6,050
Create your rewrite-rule. Something like:

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^/path/to/rewrite$ /rewrite/to 
  2.  
Then in your PHP script that needs to know whether the rewrite engine is working, call get_headers() on that URL:

Expand|Select|Wrap|Line Numbers
  1. $headers = get_headers("http://yoursite/path/to/rewrite");
  2.  
  3. if ($headers[0] == '404') 
  4.     $rewrite_engine_enabled = false;
  5.  
Something like that.
Mar 14 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.