Forum Moderators: phranque

Message Too Old, No Replies

Can I rewrite from one domain to another?

WITHOUT triggering a 301/302?

         

downhiller80

5:24 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



I can easily set up a site so that if the user types in "/page1/" it takes them to "/page.php?id=1", agreed?

I've done it many times, and it does it without sending a 301/302, and without changing the URL that the user sees in their browser.


I have an odd situation at the moment.

I need to rewrite www.domain1.com, to www.domain2.com/specificpageonthisdomain

When I've tried it using mod_rewrite it sends a redirect header and changes the user's URL in their address bar.


I presume this is intentional behaviour, designed to stop people from being able to hijack others websites? Or am I missing an easy trick that will let me accomplish what I need to do?

cheers!

DailyAmerican

5:49 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



See if this works.

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)/page(.*)/$ [domain2.com...] [NC,L]

jdMorgan

6:27 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot "rewrite" to a different domain. A rewrite, by definition, is a URL-to-internal-filepath translation.

If the domains are co-hosted in the same filespace, it may be possible to rewrite from one to the other, to alias part of the directory structure that they share (see mod_alias), or to use symlinks to make some of the files for one site appear to also reside in the filespace of the other site. The best choice will likely be based on how the file locations and permissions are already set up.

However, if the servers are separate, those server-internal methods won't work.

The remaining option is to reverse proxy the domain1 site to the domain2 site. This means that domain1 will have to handle all the requests and 'pass them on' to domain2. This also means that domain1 will log all those requests, as will domain2. However, unless you take steps to customize the headers sent from domain1 to domain2, and to customize the access logging on domain2, domain2 will see all requests as coming from domain1, and the original requestors' IP addresses will be lost. This of course makes a mess of the logs and stats on domain2 as well.

Also, this means that for every client (visitor or robot request), domain1 will have to accept and process one incoming request from the client, send an outgoing request to the back-end (domain2) server, wait for and accept its reposnse, and then forward that response back to the client. Thus one HTTP transaction becomes two, slowing things down, and site reliability is halved: A failure in either server takes the site down.

You will need to have admin privileges on both servers to do this properly, and although certainly not "impossible," it is not a trivial project. If you use them, sessions, cookies, and SSL certificates may need modifications.

If this still sounds like something you want to do, take a look at Apache mod_proxy and mod_log_config. Note the use of the X-Forwarded-For header, ProxyPreserveHost option, etc.

Jim

jdMorgan

6:49 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please observe that using any domain but "example.com" or "www.example.com" messes up your posts. While I do not wish to delete such posts which link to actual sites, neither can I afford the time needed to edit all of them.

Please use only "example.com" and "www.example.com" or break these URLs by inserting bold or italic tag pairs after "http:" if it is necessary to cite multiple example domains. Example: http://www.example-two.com/index.html can be cleanly posted by writing "http:[ b ][ /b ]www.example-two.com/index.html" without the spaces in the bold tags.

However, http://example.com and http://www.example.com can be directly posted without any additional work required by anybody.

Thanks,
Jim