How to force a browser to refresh a cached version of a webpage

前端 未结 9 598
粉色の甜心
粉色の甜心 2020-12-08 10:06

I have a website that because of an ill-prepared apache conf file has instructed users to cache a website URL several years into the future. As a result, when a person visit

9条回答
  •  感动是毒
    2020-12-08 11:08

    I realize this question is very old, but I have a viable answer:

    Of course you can force new URL's to avoid common caches (not long term ones)...

    I.e.

    • Add query to static .js/.css/.html files
    • Add meta pragma tag for no-cache
    • Server-side redirections, no cache, eliminate cookies, sessions, etc.

    However in a scenario like this (formerly edited apache .conf for long time caching) since you cannot change the domain for SEO purposes, there is a 'crude hack' you can use which will minimize the impact to SEO:

    Copy your index page (i.e. index.php) to a new page (i.e. index_new.php) and edit httpd.conf (or equivalent) so that the DirectoryIndex is the new page. Then just delete or move your old page, it should theoretically always redirect to the new page.

    I.e. in Debian/Ubuntu:

    cd /var/www
    cp index.php index_new.php
    sudo vim /etc/apache2/sites-enabled/000-default
    
        
            ...
            DirectoryIndex index_new.php
        
    
    mv index.php index_old.php
    sudo service apache2 restart
    

    And there you go.

提交回复
热议问题