Forum Moderators: phranque

Message Too Old, No Replies

redirect example.com but not example.com/others

redirect question

         

pesto

11:41 am on Sep 8, 2011 (gmt 0)

10+ Year Member



Hi,

I was asked to set up a redirection in apache, but I admit that I don't know a lot about redirection.

The situation:
example.com is hosted on an apache webserver, this also has quite a few directories beneath it like example.com/this example.com/that a.s.o. These subdirectories tend to change frequently, new ones are added, some change names or get deleted...

Now they want example.com to be redirected to another apache server (anotherexample.com), but NOT example.com/this example.com/that and so forth.

I have been reading trough the docs, and searching this (and others) forum, but until now, I can't say I have found the way to set this up. I'm also not sure what to use, mod_rewrite or mod_proxy (ProxyPass looks promising)

Option 1: mod_rewrite

RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
RewriteRule ^(.*)$ [anotherexample.com...] [R=302,L]

=> I'm having a hard time judging if this will have side-effects...

Option 2: ProxyPass
ProxyPass / [anotherexample.com...]

=> I'm not sure if ProxyPass accepts this, or if it can only do this for directories underneath. Can I also use regex here?
like e.g. ProxyPass /(.*)$ [anotherexample.com...]

Because if this is possible, I can reverse the situation, swap DNS entries for example.com and anotherexample.com, and have the ProxyPass do it's magic the other way around: keep example.com local, and redirect all subfolders

Any hints are welcome!

Thanks already!

g1smd

12:01 pm on Sep 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Redirect: User asks for URL, server tells user to make new request for new URL (on same server or on different server).

Proxy: User requests URL, server fetches content from some other server, and delivers it to user at same URL they requested.

Rewrite: User requests URL, server fetches content from some other place inside the same server, and delivers it to user at same URL they requested.

What you need hinges on whether you want to "stay" at the originally requested URL or be redirected to another URL AND whether the content is on the same server or on a different server to that that the original URL request refers.

Only after finalising those requirements can you begin to start coding.

pesto

6:13 pm on Sep 8, 2011 (gmt 0)

10+ Year Member



Thanks for clarifying g1smd!

I will hopefully get more details tomorrow. I was asked if I could do this, but I am actually a unix system engineer, so I have had dealings with apache, but not in this area. As I said however, I should be getting more details from them tomorrow.

Pt.