Home Fallback logic to redirect to a new domain using mod rewrite
Reply: 0

Fallback logic to redirect to a new domain using mod rewrite

Lokesh Agrawal
1#
Lokesh Agrawal Published in 2018-01-09 11:52:31Z

This is a followup question on Redirect to a new domain using apache vhost configuration

Requirement

I wanted my requests from somedomain.com/loadproduct?product=dell-inspiron-15 to be selectively redirected to someotherdomain.com/dell-inspiron-15 but at the same time I want to make sure if something goes wrong with the new domain(someotherdomain in the example), users are still able to use old domain by adding "/old" in the url.

For example if users uses

somedomain.com/old/loadproduct?product=dell-inspiron-15

then they should not be redirected to

someotherdomain/dell-inspiron-15

but should be served through a valid old domain url

somedomain.com/loadproduct?product=dell-inspiron-15

(problem lies here, based on the configurations in my vhost, this redirection will again redirect to someotherdomain/dell-inspiron-15).

Problem: cycle in the redirection

"somedomain.com/old/loadproduct?product=dell-inspiron-15" redirects to "somedomain.com/loadproduct?product=dell-inspiron-15" redirects to "someotherdomain/dell-inspiron-15"

Currently my vhost configuration looks like below. It redirects to someotherdomain for selected products but there is no fallback configuration.

Listen 12567 NameVirtualHost *:12567

ServerName somedomain.com ProxyPreserveHost On

RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-15) [NC,OR]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-16) [NC,OR]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-17) [NC]
RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]

Any leads here is really appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.362286 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO