Solved

Tricky mod_rewrite situation

Posted on 2006-06-30
14
342 Views
Last Modified: 2008-03-10
Consider Server X, running Apache v2.0.52 with mod_rewrite

Server X hosts mailing lists using Mailman. Mailman URLs for lists are in the form:

server.domain.tld/mailman/listinfo/<listname>

So, a mailing list named "EE" would be accessed via:

serverX.domain.tld/mailman/listinfo/EE

Now, say I decide to move list EE elsewhere - but other lists remain on Server X. I want to re-direct people trying to reach the Mailman-based web page (ONLY for list EE) to Server Y, which is also running Apache but without mod_rewrite. It is normally accessed via:

serverY.domain.tld

1) How would I go about rewriting "serverX.domain.tld/mailman/listinfo/EE" to "serverY.domain.tld" ?

2) ServerX has an existing Rewrite rule that re-writes all "http://" requests to "https://". How do I correctly interface the rule for 1 into the existing rule? Server Y does NOT support SSL, so the result of 1 should be "http://serverY.domain.tld".
0
Comment
Question by:PsiCop
  • 7
  • 6
14 Comments
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility
Hi PsiCop,

For the multiple rules situation, just create the new rules before the old and end with an L flag -- [L] to stop the rewriting after the first condition is met...

RewriteCond %{HTTP_HOST} ^serverX\.domain\.tld
RewriteRule ^mailman/listinfo/([a-zA-Z]*)$ http://serverY.domain.tld/listinfo/$1 [R=301,L]

Then have your existing rules below the above...

Hope this helps... Let me know if I misunderstood...
-Julian.
0
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility
RewriteRule ^mailman/listinfo/(.*)$ http://serverY.domain.tld/mailman/listinfo/$1 [R=301,L]

^ slight change


Or do you want to redirect only request for "serverX.domain.tld/mailman/listinfo/EE" for example?
In this case, you'd need to make a rule for each redirect and end with an L flag...

RewriteCond %{HTTP_HOST} ^serverX\.domain\.tld
RewriteRule ^mailman/listinfo/EE/(.*)$ http://serverY.domain.tld/listinfo/EE/$1 [R=301,L]
0
 
LVL 34

Author Comment

by:PsiCop
Comment Utility
That is correct - I *only* want to rerwrite "serverX.domain.tld/mailman/listinfo/EE" .... NOT any other list info pages. So "serverX.domain.tld/mailman/listinfo/OtherList" would NOT get re-written.
0
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility
Ok, in that case you'd probably need to create a rule for each redirect. Have you tried the above?
If there's nothing after the list name, you can also leave out the wildcard:

RewriteRule ^mailman/listinfo/EE/$ http://serverY.domain.tld/listinfo/EE/ [R=301,L]
0
 
LVL 34

Author Comment

by:PsiCop
Comment Utility
OK, I've tried that, and it's not working. Doesn't seem to have any effect.

Do I need BOTH RewriteCond and RewriteRule?

Does the fact that SSL is in use matter?
0
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility
<< Do I need BOTH RewriteCond and RewriteRule?
Well, that was the idea originally, but if you're just redirecting from one server to another, I don't think you actually need to use the RewriteCond. Try it with just the RewriteRule...

SSL shouldn't make a difference...

I presume mod_rewrite does generally work, otherwise you would have probably received a 500 error...
Are you getting any sort of error or message or anything?

Are the .htaccess file and the "mailman/" directory both in your root directory ?

If so, then this should work with .htaccess in your root directory:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^mailman/listinfo/EE/$ http://www.experts-exchange.com/ [R=301,L]
RewriteRule ^mailman/listinfo/EE$ http://www.experts-exchange.com/ [R=301,L]

If you type http://www.yourdomain.com/mailman/listinfo/EE/ in your browser.
The last trailing slash is important, so I've created 2 rules in case the slash is forgotten...

Let me know if the above still doesn't work.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 34

Author Comment

by:PsiCop
Comment Utility
Yes, Rewrite generally works. I use other Rewrite rules to force everything to SSL and redirect everything to Mailman. I've put these new rules before the others.

No .htaccess files at all.

No error messages. Trailing / or no trailing slash doesn't seem to make any difference.
0
 
LVL 21

Accepted Solution

by:
Julian Matz earned 500 total points
Comment Utility
Oh, ok, I was assuming you were using .htaccess, but you're probably putting it straight into your server's config file?
I haven't done that in a while, so I can't think of the exact syntax to use...

...but as far as I can remember, you can simply add a preceding slash to the rules if using httpd.conf instead of .htaccess:

RewriteRule ^/mailman/listinfo/EE/$ http://www.experts-exchange.com/ [R=301,L]
RewriteRule ^/mailman/listinfo/EE$ http://www.experts-exchange.com/ [R=301,L]
# added slash^ in front of mailman/

If that doesn't work, maybe you could post an example of an existing rule you have in the config file to help me understand the directory structure?


0
 
LVL 34

Author Comment

by:PsiCop
Comment Utility
Yes, doing this in the configuration files.

And that may have been it...the leading /

Seems to be working - I need to test it, but it's looking good, and when I get a chance to sit down and play with it to confirm, I'll award the points. Thanks!
0
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility
Great! I wish you the best of luck! Let me know if you need any more help with this...
0
 
LVL 34

Author Comment

by:PsiCop
Comment Utility
Seems to be working fine. Thanks for the help.
0
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility

You're welcome, PsiCop!
0
 
LVL 34

Author Comment

by:PsiCop
Comment Utility
I asked a Mod to re-open the Q because I accidentally selected the wrong Comment as the Answer. That's fixed. Thanks, angelIII.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now