I'm trying to permanently redirect all requests to my root directory to another site. I don't want anything other than the root requests to be redirected.

Requests to "http://www.example.com" should to to "http://www.example2.com/blah"

I can get this working with the following:

RewriteEngine On Rewriterule ^/$ http://www.example2.com/blah [L,R=301]

Everything seems to work fine (all requests other than root remain not redirected). Except that one particular type of request doesn't work.

I have a PHP script that runs at "http://www.example.com/phpscript"

Requests to that script have an extra component in the url like "http://www.example.com/phpscript/blah"

I strip out the /blah part within the PHP script and return an gif image based on the request. This may be the source of my problem. Requests to this url don't work with my above rewriterule.

Any ideas? Thanks in advance.

  • What do you mean by "don't work"? Nov 13, 2009 at 8:57
  • It seems as if that particular type of request (to "example.com/phpscript") is redirected. The url no longer returns an image as it did before.
    – user25958
    Nov 13, 2009 at 18:48

1 Answer 1


You possibly want

Rewriterule ^$ http://www.example2.com/blah [L,R=301]

(No slash)

If this doesn't work, you should try adding this to your http config (Somewhere in the config, it doesn't work at htaccess or virtualhost level)

RewriteLog /tmp/rewrite.log
RewriteLogLevel 9

This will provide you with a line by line explaination of what it's trying to match against what regex, and what the final decision is.

Remove these lines afterwards, otherwise one day you'll discover you don't have nearly as much disk space as you thought you should...

  • Hey Aquarion, thanks for the tip about the rewritelog. I found out that the site was running everything through a central PHP controller. That's what was preventing the RewriteRules from working correctly. I ended up just adding the redirect to the PHP controller and that took care of it.
    – user25958
    Nov 21, 2009 at 19:20

You must log in to answer this question.