So I'm trying to get mod_rewrite working on my new site. I've used mod_rewrite successfully a few years ago, but this time not a single command after 'RewriteEngine On' works.

I'm getting exactly the same effect on my local Apache 2.2 as I do on my web host's server, so it's not that the server isn't configured for mod_rewrite. My local machine runs Windows, and the remote server is Linux, so they're pretty independent systems. Here's what I've checked so far for my localhost:

  • The 'LoadModule rewrite_module' line in httpd.conf is not commented with a #
  • I have 'Options Indexes FollowSymLinks Includes' in place in my httpd.conf for my html directory
  • And I have 'AllowOverride All' in place beside the Options line too.
  • The .htaccess file I have in my site's root directory is being accessed. Putting nonsense in the first line gets me an Internal Server Error, removing it takes it away
  • Putting 'RewriteEngine Cheese' as the first line gets me a line in my error.log that says 'RewriteEngine must be On or Off', so it definitely seems to be ready to do some rewriting...

BUT. Nothing I type after RewriteEngine On has any effect! I can write nonsense in there and get no error message. I've put lots of commands in there as a test, but even this .htaccess file does nothing:

RewriteEngine On
RewriteRule ^.*$ test.html [R]

That should rewrite every page I go to to be test.html shouldn't it? And yet, nothing happens at all - if I go to hello.html, I just get a web page saying that hello.html isn't found.

Please can someone offer a suggestion as to what to try next?

2 Answers 2


Linux config files, including Apache config files require the last line to be empty. Everything after the last newline will be ignored.

  • Have you verified test.html exists and readable?
    – rjt
    Mar 12, 2015 at 23:17
  • test.html doesn't exist. I just want to see the 'can't find test.html' message.
    – Z M
    Mar 13, 2015 at 9:21
  • stoeff, as I've now said in my own answer, adding your blank line made it work. And so did taking the blank line away again afterwards. :-/ It's a mystery, but it's all sprung to life now. Thanks for your help.
    – Z M
    Mar 13, 2015 at 9:22

Incredible. After several days of trying to get this to work, that exact .htaccess file I posted suddenly starts working today, both locally and on my remote server. What did I do? I've no idea. I tried adding an empty last line, as the other answer advised - and then it worked. But now I've gotten rid of the empty last line, it STILL works. So I have no idea what happened. Sorry for the vague outcome here. It's a mystery to me.

It's not even like rebooting my local machine was the solution, as I haven't rebooted the remote server, and my .htaccess file has suddenly started working there too now. It's the only file I uploaded before re-testing to see if it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .