Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What do you mean by "don't work"? –  reinierpost Nov 13 '09 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 '09 at 18:48

1 Answer 1

up vote 0 down vote accepted

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...

share|improve this answer
    
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 '09 at 19:20

Your Answer

 
discard

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