Solved

Tricky mod_rewrite situation

Posted on 2006-06-30
14
343 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
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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 500 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

18 Experts available now in Live!

Get 1:1 Help Now