I want to redirect all traffic on my webpage from www to non-www. So every request that goes to www.example.com
will be redirected to example.com
.
This is done in my .htaccess (taken from this question)
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
The problem is, that I previously didn't have this rule in my .htaccess file. So if a user previously accessed the website using www.example.com
now the cache seems to prevent the redirect to example.com
and instead the www URL stays in the address bar.
If I however open a private browser window or clear the website data, the redirect works as expected.
I've tested it in both Chrome (88.0.4324.192) and Firefox (86.0), both browsers show the same behavior. OS: macOS 10.15.7
How can I fix this from a server-side perspective? Since I can't tell all users to clear their cache.
Steps to reproduce:
- Clear cache and history in browser to start with a clean session
- Open
www.example.com
- Add rewrite rule www to non-www in .htaccess file
- Open
www.example.com
again (browser should have this address in his history from the last access). No rewrite toexample.com
will happen.
EDIT:
Maybe this occurs, because the browser has content already cached for www.example.com
and thus doesn't even request the server. However the problem remains the same.