Aug 13, 2011
tom

Apache server rewrite rules: how to avoid “implicitly forcing redirect (rc=302)”?

Question

I’ve got a very annoying problem:

our webserver handles 2 (more actually but let’s say 2 for a simpler example):

  • pretassur.fr
  • pretassuragentimmobilier.fr

Here’s what I want to do:
change

(whatever1).pretassuragentimmobilier.fr(/whatever2)

to

(whatever1).pretassur.fr(/whatever2)?theme=agentimmobilier

So here’s my rewriterule:

RewriteCond %{SERVER_NAME} (([a-z]+.)*)pretassuragentimmobilier.(fr|com)
RewriteRule   ^(.+)        http://%1pretassur.fr$1 [E=THEME:pretassur_agent,QSA]
# if THEME not empty, set it :
RewriteCond   %{ENV:THEME} ^(.+)$
RewriteRule (.*) $1?IDP=%{ENV:THEME} [QSA]

The big (huge) problem is: let’s have a look at the rewrite logs:

[pretassurmandataireimmo.com] (5)
=> setting env variable 'THEME' to 'pretassur_mandataire'
[pretassurmandataireimmo.com]
=> (2) implicitly forcing redirect (rc=302) with http://pretassur.fr/

Aaaaaaaaarg! “implicitly forcing redirect” => I don’t want that ! I want to internally redirect to pretassur.fr, not to make a real redirect!

Now if you type: http://pretassurmandataireimmo.com it is redirected to http://pretassur.fr/?IDP=pretassur_mandataire (try it) I don’t want that! I want to display this page http://pretassur.fr/?IDP=pretassur_mandataire but without touching the original host!

Any idea?

Thanks a lot!

Answer

Even if they are on the same server you cannot do internal redirects between two different vhosts. Hence the external (302) redirect.

To accomplish what you want you could use the “‘proxy|P’ (force proxy)” option.

Related posts:

  1. Apache .htaccess 301 permanent redirect
  2. Apache rewrite rules behind a nginx proxy
  3. .htaccess modify rules and redirect if there’s .php in the url
  4. Why do some rewrite rules fail while AJP is serving all of my requests to Tomcat?
  5. Rewrite Conditions Backreferences passed to all rules?

Leave a comment