Results 1 to 25 of 28
-
08-28-2007, 07:16 AM #1Newbie
- Join Date
- Aug 2007
- Posts
- 23
mod_rewrite to another domain on another server
Hey,
So - I'm trying to do the following: Have multiples domains on multiple servers, with a single server handling them all. I need mod_rewrite to map:
http://www.olddomain.com/abc.php -> http://www.newdomain.com/SITE1/abc.php
But do it silently - so a [301] Redirect or similar won't do - www.olddomain.com is still the domain I want everyone to use *always*.
I've seen ProxyPass (and mod_proxy) but it appears that these need to be done at an httpd.conf-type level - how can this be achieved with mod_rewrite?
Effectively, I just want *everything* on a particular domain redirected to another domain silently in the background. In actual fact, it'll 99% of the time be on the same server - but I think the principle should be the same anyway.
I've tried:
RewriteEngine on
RewriteRule / http://sitemanager.com%{REQUEST_URI} [P]
Any help would be appreciated!
Thank you!
-
08-28-2007, 07:38 AM #2Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
mod_rewrite will only do this with the [P] flag (force proxy), which requires mod_proxy enabled. If the reason you don't want to use httpd.conf is you're trying to do this on a shared hosting account, forget it.
Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-28-2007, 07:45 AM #3Newbie
- Join Date
- Aug 2007
- Posts
- 23
mod_proxy is actually enabled - and it's a dedicated server I run. However, the control panel is a very messy one (and we won't be using this server for long - but I still need the same anyway) which has the .conf files all over the place. I attempted to edit one of them but it obviously was overridden somewhere down the line - as it didn't make a difference. So, if there's a .htaccess way that would be great. If not, I'm not sure exactly how to find the authoritative .conf file to edit.
Cheers
-
08-28-2007, 08:28 AM #4Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Ok, well the mod_rewrite way (straight from the manual) would be in httpd.conf:
Code:RewriteEngine on ^/somepath(.*) http://otherhost/otherpath$1 [P]
Code:RewriteEngine on ^localpath(.*) http://otherhost/otherpath$1 [P]
Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-28-2007, 10:17 AM #5Newbie
- Join Date
- Aug 2007
- Posts
- 23
foobic,
Thanks for the help - however, the following error appears (in /var/log/error_log)
Invalid command '^/(.*)', perhaps mis-spelled or defined by a module not included in the server configuration
And an internal server error is displayed when trying to view the site.
Any thoughts as to why?
-
08-28-2007, 10:42 AM #6Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Um, perhaps because I left out the "RewriteRule"
Code:RewriteEngine on RewriteRule ^/somepath(.*) http://otherhost/otherpath$1 [P]
Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-28-2007, 10:53 AM #7Newbie
- Join Date
- Aug 2007
- Posts
- 23
:-) I thought you had, so did try that! But, it still comes back as a 404 ... Shall I just throw the thing out the window now, or is there a logical reason?
-
08-28-2007, 04:11 PM #8Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
There's always a logical reason. Unfortunately it's usually a logical reason you didn't anticipate
Turn on rewrite logging and see what Apache thinks it's doing.Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-28-2007, 05:23 PM #9Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Options +FollowSymLinks
and if you are one level down the root directory of the virtual host:
RewriteBase /dir_name
Where ^/somepath(.*) would be ^somepath/(.*)$
-
08-29-2007, 03:50 AM #10Newbie
- Join Date
- Aug 2007
- Posts
- 23
Steve_Arm - thank you, that explains away some of the problems. I had already done the FollowSymLinks (from previous Mod_Rewrite experiences) but the RewriteBase is, now obviously, required as it is in a subdirectory. It still doesn't work, but at least we're closing in! :-)
Foobic - I've turned on RewriteLog to /var/log/rewrite - the file exists, but nothing is written there. Is there any particular reason? (I'm going to research about the permissions that RewriteLog may need, as perhaps that's not within Apaches 'reign of control' - but then, it wouldn't have been able to create it in the first place ...)
-
08-29-2007, 03:58 AM #11Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Do you want to post what you have so far?
-
08-29-2007, 04:04 AM #12Newbie
- Join Date
- Aug 2007
- Posts
- 23
Certainly:
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /testsite
RewriteRule ^/(.*) http://www.sitemanager.com/$1 [P]
RewriteLog is not logging anything. I've changed the position to one I found in one of the .conf files itself - /var/log/apache2/rewrite.log - this ensures permissions etc. But, to no avail - I've also increased RewriteLogLevel - not logging a thing.
-
08-29-2007, 04:18 AM #13Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
It works for me like this:
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /testsite
RewriteRule ^(.*)$ http://www.sitemanager.com/$1
But I haven't installed mod_proxy so I wouldn't know if the P flag is workin
-
08-29-2007, 04:19 AM #14Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Are you putting these in a VirtualHost or in the main server config?
Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-29-2007, 04:20 AM #15Newbie
- Join Date
- Aug 2007
- Posts
- 23
Here's my RewriteLog - I managed to get it going with a bit of tinkering! (This is for a single page transaction - obviously, towards the end, the rewriting is producing an error page)...
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (2) init rewrite engine with requested uri /testsite/abc.php
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (3) applying pattern '^' to uri '/testsite/abc.php'
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (2) init rewrite engine with requested uri /testsite/abc.php
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (3) applying pattern '^' to uri '/testsite/abc.php'
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (4) RewriteCond: input='' pattern='(.*)/[^/]+' => not-matched
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (1) pass through /testsite/abc.php
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (4) RewriteCond: input='/domains/m/y/myserver.co.uk/public_html/testsite/abc.php' pattern='(.*)/[^/]+' => matched
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (1) pass through /testsite/abc.php
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (3) [per-dir /domains/m/y/myserver.co.uk/public_html/testsite/] strip per-dir prefix: /domains/m/y/myserver.co.uk/public_html/testsite/abc.php -> abc.php
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (3) [per-dir /domains/m/y/myserver.co.uk/public_html/testsite/] applying pattern '^/(.*)' to uri 'abc.php'
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81dfdb0/initial] (1) [per-dir /domains/m/y/myserver.co.uk/public_html/testsite/] pass through /domains/m/y/myserver.co.uk/public_html/testsite/abc.php
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81ea9d8/initial/redir#1] (2) init rewrite engine with requested uri /.error
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81ea9d8/initial/redir#1] (3) applying pattern '^' to uri '/.error'
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (2) init rewrite engine with requested uri /.error
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (3) applying pattern '^' to uri '/.error'
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (4) RewriteCond: input='' pattern='(.*)/[^/]+' => not-matched
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81e3dc0/subreq] (1) pass through /.error
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81ea9d8/initial/redir#1] (4) RewriteCond: input='/domains/m/y/myserver.co.uk/public_html/.error' pattern='(.*)/[^/]+' => matched
123.123.123.123 - - [29/Aug/2007:09:17:49 +0100] [myserver.co.uk/sid#818e028][rid#81ea9d8/initial/redir#1] (1) pass through /.error
-
08-29-2007, 04:23 AM #16Newbie
- Join Date
- Aug 2007
- Posts
- 23
foobic - these are going in the .htaccess for that directory.
Steve - that's superb, it actually does the redirect - HOWEVER - without the [P] flag, it actually redirects the entire site *client side* so the user sees the second site. It needs to be using a proxy so they never see the second site (thus, many sites can work off the same master server without the user needing to know the specifics).
This happens *with* the [P]...
Bad Gateway!
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request /GET/testsite/
Reason: DNS lookup failure for: http://www.SITEMANAGER.com
-
08-29-2007, 04:29 AM #17Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Right now I'm testing it from a virtual host, but the directory is an Alias, so it's:
<VirtualHost 1.1.1.1:80>
# various configurations
Alias /directory /usr/home/username/public_html/directory.com
<Directory "/usr/home/username/public_html/directory.com">
RewriteEngine On
RewriteBase /directory.com
RewriteRule ^somepath/(.*)$ http://www.domain.com/$1 [L]
</Directory>
So when I call the URL it is:
http://1.1.1.1/directory.com/somepath
-
08-29-2007, 04:33 AM #18Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Maybe you want to use the directive ProxyPass
-
08-29-2007, 04:35 AM #19Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
Steve, my question was to MrSparky, but since he's got the logging working now it's irrelevant
MrSparky - have you got the correct resolver settings in /etc/resolv.conf? Can you use lynx / wget from the command line?Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-29-2007, 04:37 AM #20Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Ha! I didn't looked at the username! I thought MrSparky has written it.
-
08-29-2007, 04:51 AM #21Newbie
- Join Date
- Aug 2007
- Posts
- 23
I can wget although it comes back (correctly) as a 404... that shouldn't mess it up, should it?
I've tried ProxyPass but it wasn't working - possibly because the sites are assigned like:
Directory /*/*/*/public_html/....
(As in /m/y/mysite.com/public_html)
But using RegExp to find the correct directory based off the domain name.
So each site doesn't have it's own Directory or VirtualSite in the httpd.conf files
-
08-29-2007, 05:04 AM #22Newbie
- Join Date
- Aug 2007
- Posts
- 23
Got the b**tard!
For some reason - the bad proxy request was that it couldn't find sitemanager.MYDOMAIN.com - even though 'wget' worked fine for it.
At least I can narrow down the problems now.
Guys - Thank you SO much! Mod_Rewrite is cryptic at best! I've managed to get it to do some useful (wonderful!) things that are very basic, but sometimes it stumps me! Appreciate the help very much!!
EDIT - You'd believe me if I said it finally decided the original host was, after all, fine! And it's not DNS issues - the subdomain has been up for quite a while, not recently added! Cheers again!Last edited by MrSparky; 08-29-2007 at 05:14 AM.
-
08-29-2007, 05:38 AM #23Newbie
- Join Date
- Aug 2007
- Posts
- 23
Interesting thought - how would I only redirect traffic where there is no existing local file? The only way I can think if using a 404 page that is in another directory and transferring all that directory to the proxy - but this would require two hits to the .htaccess file and isn't 'elegant'. What would be nice would be:
RewriteRule PageIsA404
RewriteRule RegExp http://blahblah.com [P]
Any thoughts? If not, I'll just try my method, or dig deeeeep into ModRewrite manuals :-)
-
08-29-2007, 05:42 AM #24Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
RewriteCond %{REQUEST_FILENAME} !-f
Glad you got it sortedChris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
08-29-2007, 05:46 AM #25Newbie
- Join Date
- Aug 2007
- Posts
- 23
Is it possible that Mod_Rewrite is the most powerful aspect of web programming? Honestly, as an experienced PHP programmer there is absolutely NOTHING that comes close to being able to manipulate what the user sees quite so effectively!
THANK YOU!! Great help!