?
Solved

Tricky mod_rewrite situation

Posted on 2006-06-30
14
Medium Priority
?
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 21

Expert Comment

by:Julian Matz
ID: 17025284
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
ID: 17025304
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
ID: 17027183
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 21

Expert Comment

by:Julian Matz
ID: 17027327
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
ID: 17039982
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
ID: 17040004
<< 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
 
LVL 34

Author Comment

by:PsiCop
ID: 17040018
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 2000 total points
ID: 17040051
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
ID: 17040088
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
ID: 17040107
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
ID: 17050910
Seems to be working fine. Thanks for the help.
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 17051113

You're welcome, PsiCop!
0
 
LVL 34

Author Comment

by:PsiCop
ID: 17051330
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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