• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Tricky mod_rewrite situation

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
PsiCop
Asked:
PsiCop
  • 7
  • 6
1 Solution
 
Julian MatzJoint ChairpersonCommented:
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
 
Julian MatzJoint ChairpersonCommented:
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
 
PsiCopAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Julian MatzJoint ChairpersonCommented:
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
 
PsiCopAuthor Commented:
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
 
Julian MatzJoint ChairpersonCommented:
<< 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
 
PsiCopAuthor Commented:
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
 
Julian MatzJoint ChairpersonCommented:
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
 
PsiCopAuthor Commented:
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
 
Julian MatzJoint ChairpersonCommented:
Great! I wish you the best of luck! Let me know if you need any more help with this...
0
 
PsiCopAuthor Commented:
Seems to be working fine. Thanks for the help.
0
 
Julian MatzJoint ChairpersonCommented:

You're welcome, PsiCop!
0
 
PsiCopAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now