Forum Moderators: phranque

Message Too Old, No Replies

[help] subdomain wildcard worked on Apache1.3, not working on Apache 2

mod_rewrite since ugrade to Apache2

         

islandlizard

5:03 pm on Jul 20, 2010 (gmt 0)

10+ Year Member



Hi All,

I have a site that I have just moved form an Apache1.x server to Apache 2.

The site allows visitors to create minisites in the format of:

http://myname.sitedomain.com/
http://myname.sitedomain.com/about/


etc

this is then mapped to:

http://www.sitedomain.com/sites/index.php?id=myname&section=about


while the URL remains the same in the browser.

I had all this working for the past 6 yearsunder Apache 1.3 with the following lines in my vhost config:

RewriteCond %{http_host} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.islandbrides\.com [NC]
RewriteRule ^/(.*) http://www.islandbrides.com/sites/index.php?ref=%1&section=$1 [L]


Since moving to Apache 2, the rewrite is actually redirecting to the mapped URL in the browser, rather than mapping it silently and retaining the original URL

This means that all forms (using POST) are breaking as the post data is lost in the redirect, and all links are now incorrect within the mini sites.

I've scoured goole for the past 6 hours to no avail.

Can anyone help me figure out why apache 2 is handling this differently and how to fix it?

Ben

jdMorgan

5:18 am on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure why that worked under Apache 1.x, because the code specifies a 302 redirect by including a full URL in the substitution instead of just a server-relative filepath (which would yield the desired internal rewrite).

I'd suggest:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(([^.:]+\.)+)example\.com [NC]
RewriteRule ^/(.*)$ /sites/index.php?ref=%1&section=$1 [L]

Note to readers: This code is for use in a server config file outside of any <Directory> container. For use in .htaccess or for use in a <Directory> container in a server config file, remove the leading slash from the RewriteRule pattern.

Jim