21

I had a .htaccess file doing a very simple rewrite of the page names. This is the contents of the file:

Options +FollowSymlinks
RewriteEngine on
RewriteRule setup setup.php [NC]

I now want to stop rewriting setup to setup.php - how do I do this? I've tried removing the line from the file, I've tried deleting the file and restarting apache, and it is still rewriting setup to setup.php. How do I make it stop? It seems to be completely ignoring any other .htaccess file I create, and there's nothing being written to the error log. Is it caching the file somewhere? How do I stop it?

I'm using apache2 on ubuntu.

6
  • Also, before you ask, my browser is not caching the page. I checked that already.
    – Benubird
    Commented Dec 21, 2010 at 13:08
  • Did you put this rule in your httpd.conf or some conf.d file? Are you sure you're editing the right .htaccess file? Their contents are not cached, they are read on every request. Commented Dec 21, 2010 at 13:15
  • it's a file called .htaccess, in the directory /var/www. If I put other files in that directory, they are available at the web root, so I know it's the right place.
    – Benubird
    Commented Dec 21, 2010 at 15:32
  • 5
    I had the same problem, in my case the browser cached the url redirects Commented Mar 13, 2012 at 22:21
  • My browser (firefox) also cached it. Don't know why, but it did !
    – beluga
    Commented Feb 28, 2013 at 14:47

4 Answers 4

23

If you are having problems with the htaccess file not updating due to the redirect getting cached in your browser. You can use a webkit browser like Google Chrome or Safari to open a private browsing session or Incognito Window.

Every time you update the htaccess file, you will need to close all incognito windows/tabs and then open a new one. The incognito window will not write to the cache beyond the current session and will not use the existing cache on initial load. It makes a great way to bypass caching issues when testing, and a great way to see if the issue you are having is caused by your browser's cache.

I am not sure, but Firefox and newer versions of IE might have a similar feature.

3
  • 5
    In Chrome you can open the dev tools, select the settings icon and enable "Disable cache (while DevTools is open)" as well.
    – mgutt
    Commented Jan 30, 2014 at 19:18
  • 1
    Note that this question is about an internal rewrite that appears to be cached by the server. External redirects that are cached by the browser are a different problem.
    – MrWhite
    Commented Jan 23, 2015 at 9:44
  • Note that this question may or may not be about an internal rewrite, because it is hard to test if the browser is caching it. Nothing was ruled out.
    – Jake
    Commented Jan 28, 2018 at 4:02
20

The problem is that MultiViews is enabled. MultiViews automatically adds extensions to any requested URLs, if possible. This has nothing to do with your RewriteRule; it just so happens that you were rewriting setup to setup.php so MultiViews and your rule were doing the same thing.

Add -MultiViews to the Options directive to disable it.

2
  • Debugging these types of issues can be the worst. So glad I found your answer early on =) +1
    – gerbz
    Commented Aug 10, 2015 at 22:37
  • 1
    @nitro2k01 sorry but how exactly to do this? What is options directive? I'm on mamp pro local host, code igniter framework, mac yosemite.
    – angry kiwi
    Commented Dec 29, 2015 at 4:00
1

1) Check to make sure nginx is not causing problems for you - I just turned it off, but I'm sure there are ways to set it up properly if you want to use it. (For me it was set on by default on MediaTemple's newest DV servers).

2) Try adding this to httpd.conf or vhost.conf or some other configuration file further up the food chain from your home directory's htaccess file:

Header merge Cache-Control no-cache env=NO_CACHE
Header merge Cache-Control no-store env=NO_STORE
-2

The solutions is, to open the file /etc/apache2/sites-available/default and change this:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

Into this:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

Note the AllowOverride directive - this file apparently overrides all other instructions elsewhere.

5
  • That's what you would do if .htaccess didn't work at all. That's not Benubird's problem.
    – nitro2k01
    Commented Mar 23, 2011 at 1:43
  • 1
    Oh wait, it's your own reply... I still don't see how it is related, though.
    – nitro2k01
    Commented Mar 23, 2011 at 1:49
  • 1
    @nitro2k01 Honestly, neither do I- I just did things randomly, then undid them and tried something else, until I found something that worked. Which is why I didn't accept this; I'm still hoping someone can explain it, but htaccess is deep magic.
    – Benubird
    Commented Mar 23, 2011 at 9:05
  • Try mine and compare Options +MultiViews and Options -MultiViews in the .htaccess. AllowOverride All is a prerequisite to being able to override the MultiViews (or any other) option, though. (Assuming /var/www/ is your http dir. Otherwise the change you did has no effect.)
    – nitro2k01
    Commented Mar 23, 2011 at 11:15
  • I wonder if the cache didn't just get updated around the time this change was put in place, because it does seem unrelated. I was fighting an htaccess issue recently that was driving me nuts and it was definitely just a cached redirect separate from the cache of the actual page.
    – Jake
    Commented May 14, 2012 at 17:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.