Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am reorganizing the link structure of a dynamic php-based site of mine. What I am trying to obtain is:

  • redirect old links onto new ones;
  • create new RewriteRules for new links, since every 'link' to an html page is mapped onto a php page with parameters.

The only .htaccess file is contained in the website root folder. There are no other .htaccess files in subfolders.

Till today I had no problems in reorganizing links by modifying the rules in .htaccess. Since yesterday I have been experiencing a strange problem: it looks like modifications to the .htaccess file are not immediately read by the Apache web-server, that keeps applying the old rules even if they are no longer contained in the .htaccess file. For example, I have a rule that performs the following mapping:

/cat-a/subcat-b/page.html -> /file.php?cat=cat-a&subcat=subcat-b

If I modify that rule as follows:

/cat-a/subcat-b/page.html -> /file.php?XXcatXX=cat-a&subcat=subcat-b

Apache keeps rewriting URLs according to the old (cat=cat...) format for a while. The new format (XXcatXX=...) is used only after a random lapse of time. Random meaning that I could not find any pattern in the way it behaves.

Furthermore, if I delete a rule, Apache keeps using the deleted rule for a while.

The only regularity I have found concerns new rewrite rules: Apache reads them immediately and starts using them. If I delete a rule or modify an existing one, Apache ignores the changes for a while.

I am noticing this problem only on RewriteRule instructions and not on redirections. Since redirections and rewritings are managed by different modules, I assume that I have to modify some settings in the mod_rewrite configuration.

I made some searches but was not able to find any information/documentation on this behaviour. May be there is something that I ignore and I am missing.

Are there some settings I have to worry about? Have you ever experienced a similar problem?

I am using XAMPP on a Mac OS SnowLeopard machine.

Thanks. Regards. A.

share|improve this question

migrated from stackoverflow.com Aug 28 '11 at 16:06

This question came from our site for professional and enthusiast programmers.

1 Answer 1

I am using XAMPP on Windows 7, and was experiencing the same issue. From my experimentation it appears that the caching of redirects is being carried out by the web browser, not Apache.

To demonstrate:

  • Add the following rule to your .htaccess file: RewriteRule ^fail/?$ fail.php [L,R=301]
  • Visit /fail in your web browser. You should be redirected to fail.php
  • Change the reference in your .htaccess file from fail.php to fail2.php
  • Visit /fail in your web browser again.
  • You should be redirected to fail2.php, but you end up at fail.php
  • Now visit /fail in a different web browser on the same machine, you should end up correctly at fail2.php.

The browser that was giving me issues was Firefox 6.0.

It appears that newer web browser will cache HTTP 301 redirects locally - they are defined as a permanent redirect, so should never change. However it's a pain when you are a developer and still working on a site and changing things.

share|improve this answer
    
+1. Just it's not newer browsers only -- Firefox has it since v3 for sure. That's why I use 302 when testing redirects (unless it is very simple redirect). When I see that it works as intended I'm changing it to 301. The only way around such browser behaviour is to clear caches and restart it after that. –  LazyOne Aug 28 '11 at 16:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.