2

How can a client detect if a server is using mod_rewrite? Now I know that some mod_rewrite rules are not very obvious. But some are, such as "SEO Friendly Urls". What types of behavior is impossible unless a server is running mod_rewrite?

rook
  • 66,304
  • 38
  • 162
  • 239
  • There is no behaviour that is *entirely* impossible, but there are patterns that occur extremely rarely without mod_rewrite. – Pekka Feb 01 '11 at 18:22
  • Note that there is not only one web server software. – Gumbo Feb 01 '11 at 18:37
  • @Gumbo♦ True, but the vast vast majority of web servers online are Apache. If you know of another method for some strange HTTPD i'll give you a +1. – rook Feb 01 '11 at 18:41
  • [Almost every web server software has a similar module/feature.](http://en.wikipedia.org/wiki/Rewrite_engine#Web_frameworks) – Gumbo Feb 01 '11 at 18:58

1 Answers1

4

What types of behavior is impossible unless a server is running mod_rewrite?

The real answer is "none". In theory, any URL could be formed by actual files or directories, including the classical "SEO friendly" URLs.

There is only circumstantial evidence:

  • The best indication that I can think of is when the entire site structure consists of URLs without .htm .php .html file extensions:

    http://domain.com/slugs/house-warming-party
    

    to exclude the possibility of that URL being a directory, request

    http://domain.com/slugs/house-warming-party/index.htm
    http://domain.com/slugs/house-warming-party/index.html
    http://domain.com/slugs/house-warming-party/index.php
    http://domain.com/slugs/house-warming-party/index.asp
    ... whatever other extensions there are .....
    

    if those requests all fail, it is very likely that the site is using mod_rewrite. However if they succeed, as @Gumbo says, it could also be the MultiViews option fixing the request. Either way, this is nowhere near safe!

  • Depending on what your use case is, you could also try to deduct things from the CMS used on the site. Wordpress with mod_rewrite turned on will show a different URL structure than with it turned off. The same holds true for most other CMSes. But of course, this is also a highly imperfect approach.

  • The use of HTML resources with a .html/.htm/.php ending would point slightly against the use of mod_rewrite, but you can never be sure.

  • The use of the PATHINFO variable (also known as poor man's mod_rewrite) would point somewhat strongly against the use of mod_rewrite:

    http://example.com/index.php/slugs/house-warming-party 
    

In conclusion, mod_rewrite (like most URL-rewriting tools) is supposed to be a module transparent to the outside world. I know of no sure-fire way to detect it from outside, and there may well be none.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088