Simple mod_rewrite Problem


I’m trying to do what I thought would be a simple mod_rewrite.

Basically I just want to send all URLs that aren’t a directory or file to index.php.

Here is what I have so far:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test_server/xazure/

RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

(Look familiar? It’s because I basically copied it from Wordpress).

Now, it does properly send me to the index. The problem though is that it also changes my URL. I want it to keep the URL that was typed, just change what is shown.

For example, if I type “” I want the URL to visibly stay the same (the address bar still shows that URL), but the page that is loaded is “”.

I’m running this locally with XAMPP. Is it possible that this is a server setting issue and not a .htaccess problem? If so, what option(s) might I need to change. As far as I remember, everything is default still.

Thanks a bunch!

Okay, I did some more testing and I discovered if I just have one fake folder, it works.

For example, if I do:, it works just fine. If I make it /books/5, it redirects to

Any ideas?


First, a “standard rant:”

[rant #4][indent]The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> … </IfModule> wrapper is the same thing in the webmaster world. DON’T BE AN IDIOT! If you don’t know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache’s resources (and should NEVER be allowed on a shared server).[/indent][/rant 4]

Second, I didn’t see anything which would redirect to the naked domain. Is that all you have in your .htaccess?



Thanks DK.

Yeah, I fully deserve that rant… I never use it myself, but I copied that from Wordpress and didn’t both taking it out when I posted that. It is out now though. =)

As for pointing to the naked domain, it’s not supposed to (sorry, forgot to clarify that… kinda important, eh?). It should be pointing to http://localhost/test_server/xazure/.


P.S. Just to clarify, that is my complete .htaccess at the moment.

Okay, some more playing around…

Apparently… it works…

-feels so stupid-

For some unknown reason I think Firefox cached the URL I was testing as redirecting to my base. I tried other things and they worked. I then flushed my DNS and suddenly they all work. I had no idea it would cache something like that.

Anyone have an explanation? Is it Firefox-specific, or is there some area of web development that I’ve been missing for years?


Hi sam!

Thanks for understanding the rant. To your credit, it appears that you knew about it which puts you far out in front of most others. Obviously, I see that nonsense so often that it pushes my buttons to the extent that I created an AutoHotkey code to insert the rant automatically - nothing personal, I can assure you.

The test_server/xazure/ is due to that RewriteBase. That’s another rant of mine (not a “standard rant” yet) as it’s meant to UNDO mod_alias Redirects. If you have no Redirects, you should comment that line out.

Ah, you’ve joined the club, eh? I feel STUPID most of the time! Back to your post, though, IE is known to be FAR worse as you must empty its cache to have any hope of viewing the current state of a script - at least FireFox allows a Shift-Reload to eliminate that problem. Believe me, the way that some of my clients want their websites created makes me thankful that browsers have a cache!



Thanks for the tip about RewriteBase. I completely misunderstood that. I thought it was meant to be like the base element of HTML, so I could have stuff like /index.php.

Mod rewrites and Apache settings are definitely my weakest area, so I’m always glad to learn more. =)



More often than not, I’ve got to check my memory by searching at While their docs are “geeky,” they do contain a LOT of useful information.