5

Why is my mod_rewrite doing this?

add path info postfix: /home/mobelluk/public_html/about.php -> /home/mobelluk/public_html/about.php/

which results in an unwanted trailing slash on EVERYTHING.

I have disabled all my .htaccess rules so they're out of the equation.

Chris J Allen
  • 18,970
  • 20
  • 76
  • 114

4 Answers4

22

apparently there's been an issue with mod_rewrite re-appending post-fix part in certain cases https://issues.apache.org/bugzilla/show_bug.cgi?id=38642

The problem:

If multiple RewriteRules within a .htaccess file match, unwanted copies of PATH_INFO may accumulate at the end of the URI.

If you are on Apache 2.2.12 or later, you can use the DPI flag to prevent this http://httpd.apache.org/docs/2.2/rewrite/flags.html

Ivan Solntsev
  • 2,081
  • 2
  • 31
  • 40
econstantin
  • 791
  • 1
  • 7
  • 15
  • 1
    The `DPI` flag basically means "fix mod_rewrite bug". You should use it in every `RewriteRule` you ever write if you don't want to be caught out by this bug. – Jake Mar 26 '18 at 22:18
4

In searching for "add path info postfix", this question comes up first and while it eventually did solve my problem, it took me almost 2 hours to understand what was going on. In working on a site, I needed this rewrite:

/resources/band/ -> resources.html?section=band

Accomplished with this mod_rewrite:

RewriteRule ^resources/(.*)/$ resources.html?section=$1 [L]

Changing that to [DPI] did nothing... The code on my resources.html page was 100% for sure being called but the argument of section=band was not being sent to it.

Get this... in case you find Apache's documentation impossible to read, Multiviews is the problem. When the browser sees that multiviews is on the server sees /resources/band/ and say "Oh, I'm so smart, I know what that means!" and redirects:

/resources/band/ -> /resources.html/band/

True story! I changed the +Multiviews to -Multiviews on the virtual host - problem instantly solved.

Scott
  • 695
  • 1
  • 8
  • 16
2

Is it possible the new server has mod_dir loaded, with DirectorySlash On where the old one did not and that is leading to this problem?

(Note that DirectorySlash On is the default if mod_dir is loaded and nothing is overriding it)

Grant Wagner
  • 25,263
  • 7
  • 54
  • 64
2

I solved this issue by disabling MultiViews in my virtual host Options configuration. I was rewriting something similar to below:

Desired rewrite:

/dir/ -> /dir.html

Actual translations:

/dir/ -> /dir.html (MultiViews)
/dir.html -> /dir.html/ (mod_rewrite: 404, didn't exist)

Disabling MultiViews kept the initial translation from taking place. I could have probably adjusted the rewrite rule to compensate for this, but I wasn't using MultiViews for anything else anyway.

The following post tipped me off on this issue: https://velenux.wordpress.com/2012/07/17/apache-mod_rewrite-multiple-add-path-info-postfix/#comment-1476

mikepj
  • 1,256
  • 11
  • 11