1

This isn't exactly a problem, but I'm really curious. I'm doing a simple rewrite in my .htaccess file with the [L] flag. It works fine, as expected in GUI browsers, but I see a quirk when I load the page in w3m. It still redirects as expected, but when I press Shift-U to see the URL, it shows the folder to which it has been redirected. I thought that unless I'm using the [R] flag, the browser would not even know that Apache is pulling the page from a different directory. Am I wrong, or do I have .htaccess configured incorrectly? Here's .htaccess:

RewriteEngine On
Options -Indexes
RewriteRule     ^unicorn/?$      sampler/cs5.html [L]
RewriteCond     %{REQUEST_URI} !^/addip/?$
RewriteCond     %{REQUEST_URI} !^/sampler/
RewriteCond     %{REQUEST_URI} !^/cs.*
RewriteRule     ^([a-zA-Z0-9]+)$                /makestory/makestory.php?story=$1 [END]

Here's the URL I put in w3m: https://example.com/unicorn. Typical browsers continue to show this in their address bar.

Here's what w3m shows when I press Shift-U: https://example.com/sampler/

Thoughts?

LedLincoln
  • 31
  • 4
  • This is indeed surprising. Internal rewriting is nothing an _external_ client can even see. You _could_ dig deeper, using a network sniffer for example to actually see the details of the rewriting process. I could imagine some effect based on the fact that the browser capabilities of such a browser are certainly very different from a normal one. And that this leads to some slightly different behavior on the server side, maybe connected to content negotiation which then indeed triggers an external redirection for this specific request. That is just a wild guess, though. – arkascha Dec 02 '21 at 20:48
  • 1
    "`https://example.com/sampler/`" - although this isn't the _file_ you are rewriting to (`sampler/cs5.html`). Are you referencing the `/sampler/` subdirectory anywhere in the HTML of the page? `rel="canonical"` perhaps? – MrWhite Dec 03 '21 at 01:10
  • 1
    You nailed it, MrWhite! The html doc contained . I took that out, and w3m now shows https://example.com/cookie, as expected. I then fixed the reference to the css file so that base href isn't needed anyway. Thanks for the insight. – LedLincoln Dec 03 '21 at 21:17
  • Glad you resolved it. You should add that as an answer (and later “accept”) as this could help other readers. :) – MrWhite Dec 04 '21 at 00:20

1 Answers1

2

You nailed it, MrWhite! The html doc contained <base href="/sampler/">. I took that out, and w3m now shows example.com/cookie, as expected. I then fixed the reference to the CSS file so that base href isn't needed anyway. Thanks for the insight.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
LedLincoln
  • 31
  • 4