Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:01:16+00:00 2026-06-04T15:01:16+00:00

I have a piece of PHP software that does beautifull things with mod_rewrite. But

  • 0

I have a piece of PHP software that does beautifull things with mod_rewrite. But the same software should run on a server where mod_rewrite isn’t installed. Can I check in my php code if mod_rewrite is installed AND if a certain rule is applied?

For example, something like this:

    if ((mod_rewrite is enabled) and (mod_rewrite_rule is OK)){
        return  createBeautifullLink();
    }else{
        return createUglyLink();
    }

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:01:17+00:00Added an answer on June 4, 2026 at 3:01 pm

    use this:

    in .htaccess

    <IfModule mod_rewrite.c>
       # inform php that mod_rewrite is enabled
       SetEnv HTTP_MOD_REWRITE on
       ...
    

    in PHP:

    $mod_rewrite = FALSE;
    if (function_exists("apache_get_modules")) {
       $modules = apache_get_modules();
       $mod_rewrite = in_array("mod_rewrite",$modules);
    }
    if (!isset($mod_rewrite) && isset($_SERVER["HTTP_MOD_REWRITE"])) {
       $mod_rewrite = ($_SERVER["HTTP_MOD_REWRITE"]=="on" ? TRUE : FALSE); 
    }
    if (!isset($mod_rewrite)) {
       // last solution; call a specific page as "mod-rewrite" have been enabled; based on result, we decide.
       $result = file_get_contents("http://somepage.com/test_mod_rewrite");
       $mod_rewrite  = ($result=="ok" ? TRUE : FALSE);
    }
    

    The first (apache) can be disabled by server, the second custom one will exist in $_SERVER only if mod_env is installed.
    So what i think as best solution is to create a fake url redirection in your .htaccess that points to some file of yours (that return simply an “ok”) and call that with the redirection from a .php; if returns “ok”, you can use clean urls…
    The redirection code in .htaccess might looks like:

    <IfModule mod_rewrite.c>
       ...
       RewriteEngine on
       # fake rule to verify if mod rewriting works (if there are unbearable restrictions..)
       RewriteRule ^test_mod_rewrite/?$    index.php?type=test_mod_rewrite [NC,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have piece of code that works fine on my local test server but
I have a JS/PHP piece of code that selects from a database, does some
I have a PHP page that returns a piece of HTML to set the
I have a string that I want to have PHP read as a piece
Ok so I got this piece of vendor software that they said should be
I have a piece of PHP code that is generating over 6000 queries to
I have a piece of PHP code running on Windows that I have scheduled
I have a piece of codes that resizes a .png file in php. It
I have a piece of jquery code that isn't firing correctly in IE (8
I have a piece of PHP that is trying to do this: 1) given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.