0

I have a really simple mod_rewrite rule:

<Directory "/local/foobar.com/">
  RewriteEngine On
  RewriteBase /
  RewriteRule ^test$ hello/ [R]
</Directory>

In Chrome, when I go to www.foobar.com/test, I get redirected to www.foobar.com/hello/, but in IE9, no redirection happens - what am I missing?!

Further info

As requested in a comment, log output:

Chrome:

192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (3) [perdir /local/foo.com/] strip per-dir prefix: /local/foo.com/test -> test
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (3) [perdir /local/foo.com/] applying pattern '^test$' to uri 'test'
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (2) [perdir /local/foo.com/] rewrite 'test' -> 'hello/'
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (3) [perdir /local/foo.com/] add per-dir prefix: hello/ -> /local/foo.com/hello/
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (2) [perdir /local/foo.com/] explicitly forcing redirect with http://foo.com/local/foo.com/hello/
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (2) [perdir /local/foo.com/] trying to replace prefix /local/foo.com/ with /
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (1) [perdir /local/foo.com/] escaping http://foo.com/hello/ for redirect
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420002978/initial] (1) [perdir /local/foo.com/] redirect to http://foo.com/hello/ [REDIRECT/302]
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420006998/initial] (3) [perdir /local/foo.com/] add path info postfix: /local/foo.com/hello -> /local/foo.com/hello/
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420006998/initial] (3) [perdir /local/foo.com/] strip per-dir prefix: /local/foo.com/hello/ -> hello/
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420006998/initial] (3) [perdir /local/foo.com/] applying pattern '^test$' to uri 'hello/'
192.171.135.86 - - [16/Nov/2015:17:56:39 +0000] [foo.com/sid#7f4458ffddc8][rid#7f4420006998/initial] (1) [perdir /local/foo.com/] pass through /local/foo.com/hello

IE9:

192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (3) [perdir /local/foo.com/] strip per-dir prefix: /local/foo.com/test -> test
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (3) [perdir /local/foo.com/] applying pattern '^test$' to uri 'test'
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (2) [perdir /local/foo.com/] rewrite 'test' -> 'hello/'
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (3) [perdir /local/foo.com/] add per-dir prefix: hello/ -> /local/foo.com/hello/
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (2) [perdir /local/foo.com/] explicitly forcing redirect with http://foo.com/local/foo.com/hello/
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (2) [perdir /local/foo.com/] trying to replace prefix /local/foo.com/ with /
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (1) [perdir /local/foo.com/] escaping http://foo.com/hello/ for redirect
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f440c00a9b8/initial] (1) [perdir /local/foo.com/] redirect to http://foo.com/hello/ [REDIRECT/302]
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f44101b7688/initial] (3) [perdir /local/foo.com/] add path info postfix: /local/foo.com/hello -> /local/foo.com/hello/
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f44101b7688/initial] (3) [perdir /local/foo.com/] strip per-dir prefix: /local/foo.com/hello/ -> hello/
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f44101b7688/initial] (3) [perdir /local/foo.com/] applying pattern '^test$' to uri 'hello/'
192.171.135.86 - - [16/Nov/2015:18:01:45 +0000] [foo.com/sid#7f4458ffddc8][rid#7f44101b7688/initial] (1) [perdir /local/foo.com/] pass through /local/foo.com/hello
ChrisW
  • 101
  • 4
  • I'm assuming you're using Apache based on the config snippet. What version are you running and have you tried enabling the rewrite log to get some extra info on what's going on? – David King Nov 16 '15 at 17:39
  • @DavidKing Oops - sorry, yes - I am using Apache: `apachectl -v` returns `Server version: Apache/2.2.15 (Unix)` - I haven't enabled the rewrite log (I didn't even know about it...) – ChrisW Nov 16 '15 at 17:41
  • http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog will get you the info you need. Essentially you need to add `RewriteLog /path/to/log/file.log` and `RewriteLogLevel 3`. Just be warned...if this is a high volume server it will generate a LOT of output. – David King Nov 16 '15 at 17:44
  • @DavidKing Hmm, I've got a log file generated now :) - the output from a Chrome request looks exactly the same as an IE request! – ChrisW Nov 16 '15 at 18:04
  • Can you post the log entries from each? My guess is that it's related to the specific HTTP code that Apache is using to send the redirect. You may need to change the `[R]` to be something like `[R,L=301]` to force Apache to use a code that IE9 will recognize. – David King Nov 16 '15 at 18:06
  • I was a bit reluctant to use 301 because of the apparent _feature_ in IE9 that makes a 301 so permanent it persists after clearing history and cache (http://agsci.psu.edu/it/how-to/topics/web/plone/other/internet-explorer-9-permanently-caches-redirects)! Is a 302 likely to help? – ChrisW Nov 16 '15 at 18:09
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/31665/discussion-between-david-king-and-chrisw). – David King Nov 16 '15 at 18:09

1 Answers1

0

I eventually realised what was happening. I didn't actually have a folder called hello - I just wanted to test an abstract mod_rewrite rule. It seems that Chrome will follow redirects regardless of any http codes that are returned, but that IE won't show the redirect if a 404 is subsequently returned.

Once I added a folder called hello, IE did follow the rule.

ChrisW
  • 101
  • 4