Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 14th, 2001, 12:22 PM
beardo's Avatar
beardo beardo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Cheltenham, UK
Posts: 197 beardo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 11 m 13 sec
Reputation Power: 8
Unhappy

oh my deary me....

I have spent all day trying to do something and it hasn't worked. I'd appreciate it if anyone knows the answers!

I want to use mod rewrite to redirect domains using an external mapping file. This will then mean that updates can be carried out without reloading the webserver -right?

Ok,

1. I made a domain map file like so:

#######################

domain1.com http://www.domain1pointshere.com
domain2.com http://www.domain2pointshere.com
domain3.com http://www.domain3pointshere.com

#######################

I put this in: /home/httpd/conf/domain.map

2. I modified httpd.conf to include the following block:

#######################

# Activate rewriting
RewriteEngine on

# Tell Apache what/where the rewrite maps are. int:tolower is an internal
# map which converts a string to lower case.
RewriteMap domainmapping txt:/home/httpd/conf/domain.map
RewriteMap lowercase int:tolower

# Get the requested hostname, (http://THIS BIT/) convert it to lower case,
# strip off 'www.' if present, look it up in /home/httpd/conf/domainmap, and
# found, send out a redirect to that address.
#
# If not found, the URL will remain unchanged, and Apache will deal with
# it as normal.
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.)?(.+)$
RewriteCond ${domainmapping:%2} ^(.+)$
RewriteRule ^.*$ %1 [L]

#######################

3. I restarted apache.

4. I tried out the rule by visiting the domain names

5. I started to pull my hair out as all of the names pointed at the server root rather than redirecting to their new locations.

6. I went back to apache.org and read some more, figured I had it right - but it won't work.


So, what is wrong?

Server spec:

apache 1.3.19 (on redhat 6.1)

I know that mod rewrite is working as a mapping like so works perfectly well:

<VirtualHost domainname.com www.domainname.com>
ServerName domainname.com
RewriteEngine on
RewriteRule ^(.*)$ http://anotherdomain.com/$1 [P]
</VirtualHost>

If any one can help I will mail them 6 cold beers by priority mail - anywhere in the world .

Thanks,

Beardo

Reply With Quote
  #2  
Old April 15th, 2001, 07:27 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> This will then mean that updates can be carried out without reloading the webserver -right?

Yup.

Your rule looks fine to me and I think it should work. If you insist it doesn't, add two lines in bold should give you more info.

RewriteEngine on
RewriteLog "/system/path/to/rewrite.log"
RewriteLogLevel 9
RewriteMap domainmapping txt:/home/httpd/conf/domain.map
RewriteMap lowercase int:tolower
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.)?(.+)$
RewriteCond ${domainmapping:%2} ^(.+)$
RewriteRule ^.*$ %1 [L]

>> If not found, the URL will remain unchanged, and Apache will deal with it as normal

Right, but for performance concern, I would change your rule like so:

RewriteEngine on
#RewriteLog "/system/path/to/rewrite.log"
#RewriteLogLevel 9
RewriteMap domainmapping txt:/home/httpd/conf/domain.map
RewriteMap lowercase int:tolower
# The following two lines saves Apache some load without applying any lowercase or domainmapping if HTTP_HOST is exactly your www.yourdefaultdomain.com
RewriteCond %{HTTP_HOST} ^www\.yourdefaultdomain\.com$
RewriteRule ^(.+) - [L]
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.)?(.+)$
RewriteCond ${domainmapping:%2} ^(.+)$
# I would explicitly redirect with the [R], then [L] (last it) as [R,L]
RewriteRule ^.* %1 [R,L]

Reply With Quote
  #3  
Old April 15th, 2001, 10:25 AM
beardo's Avatar
beardo beardo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Cheltenham, UK
Posts: 197 beardo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 11 m 13 sec
Reputation Power: 8
thanks freebsd.

will try it out and let you know how it goes.

I think the problem is that the requests are being seen as http 1.0 and not 1.1.

beardo

Reply With Quote
  #4  
Old April 17th, 2001, 02:14 AM
beardo's Avatar
beardo beardo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Cheltenham, UK
Posts: 197 beardo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 11 m 13 sec
Reputation Power: 8
no joy I'm afraid - back to the drawing board.

Thanks for the suggestion.

Beardo

Reply With Quote
  #5  
Old April 17th, 2001, 06:38 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> no joy I'm afraid

Have you tried rewrite.log? What do you mean no joy? It logged nothing or what? Why don't you post those here. What is not working now? All request to those domains fall back to your defaultdomain?

Where did you put those lines? Within your default (1st) <VirtualHost> block?

Make sure your UseCanonicalName is set to off and the line ServerName outside of <VirtualHost> is commented out.

Reply With Quote
  #6  
Old April 17th, 2001, 07:15 AM
beardo's Avatar
beardo beardo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Cheltenham, UK
Posts: 197 beardo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 11 m 13 sec
Reputation Power: 8
Hi freebsd,

It now works , but not quite how I expected it to!

I had not set UseCanonicalName to off .

I greatly appreciate your help freebsd - can I push my luck and ask one more question?

If I my domain map file is like this:

domain1.com http://domainsomewhereelse.com

Is there any way to retain domain1.com in the browser window? As soon as you type domain1.com and hit enter domain1.com is replaced with http://domainsomewhereelse.com in the browser window.

I know that the following does that and acts like a proxy:

<VirtualHost domainname.com www.domainname.com>
ServerName domainname.com
RewriteEngine on
RewriteRule ^(.*)$ http://anotherdomain.com/$1 [P]
</VirtualHost>

But can the method above do it?

Thank you once again for your help - where should i send those beers?

Beardo

Reply With Quote
  #7  
Old April 22nd, 2001, 07:54 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I don't know why my codes didn't work out for you. Anyhow, I just rewrite everything and tested it with the addition of the proxy you requested.

RewriteEngine on
#RewriteLog "/system/path/to/rewrite.log"
#RewriteLogLevel 9
RewriteMap domainmapping txt:/home/httpd/conf/domain.map
RewriteMap lowercase int:tolower
RewriteCond %{HTTP_HOST} ^www\.yourdefaultdomain\.com$
RewriteRule ^(.+) - [L]
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.)?(.+)$ [NC]
RewriteCond ${domainmapping:%2} ^(.+)$ [NC]
# Do not remove this line or a request of http://www.yourdomain.com/path/file.html won't work.
RewriteRule ^/(.*)$ %1/$1 [P,L]
RewriteRule ^.*$ %{HTTP_HOST}=%1 [C]
RewriteRule ^/(.*)$ $1 [P,L]

If it doesn't work still, please show me the rewrite.log.

Sorry for the delay, I just got back from Las Vegas not long ago

Reply With Quote
  #8  
Old April 22nd, 2001, 08:14 AM
beardo's Avatar
beardo beardo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Cheltenham, UK
Posts: 197 beardo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 11 m 13 sec
Reputation Power: 8
Hi Freebsd,

I am coding today so will try the proxy version out - thank you very much for your assistance.

I will come back shortly and let you know how it went.

The code did work - just not as I expected, ie. it redirects the domains in the domain map file - just without proxy that's all.

Beardo
__________________
beardo ;0)
-------------------------------

Reply With Quote
  #9  
Old April 22nd, 2001, 08:23 AM
beardo's Avatar
beardo beardo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Cheltenham, UK
Posts: 197 beardo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 11 m 13 sec
Reputation Power: 8
Talking Genius

Freebsd!

What can I say, you are a very clever person ;0)

That works very well indeed, please check your private messages.

Thank you.

Beardo

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > mod rewrite


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway