|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
>> 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] |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
||||
|
||||
|
no joy I'm afraid - back to the drawing board.
Thanks for the suggestion. Beardo |
|
#5
|
|||
|
|||
|
>> 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. |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
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 ![]() |
|
#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) ------------------------------- |
|
#9
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > mod rewrite |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|