0

I have an apache vhost configurations as below. I want all my requests from

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

to be redirected to

someotherdomain.com/dell-inspiron-15.

Can I do this from vhost configuration? Note that I have query parameters in the url.

Listen 12567
NameVirtualHost *:12567

<VirtualHost *:12567>
    ServerName somedomain.com
    ProxyPreserveHost On

    RewriteEngine On
    RewriteRule ??
</VirtualHost>

Any leads here is really appreciated.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ThinkGeek
  • 4,749
  • 13
  • 44
  • 91

1 Answers1

1

You can use (instead of RewriteRule ??):

RewriteCond %{QUERY_STRING} (?:^|&)product=([^&]+) [NC]
RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]
Croises
  • 18,570
  • 4
  • 30
  • 47
  • I didn't get what "external redirect from actual URL to pretty one" and "internal forward from pretty URL to actual one" mean here? – ThinkGeek Nov 26 '17 at 15:27
  • But why is this rewrite "someotherdomain.com/dell-inspiron-15 to somedomain.com/loadproduct?product=dell-inspiron-15" needed? – ThinkGeek Nov 26 '17 at 15:37
  • My someotherdomain is self sufficient to respond to query it receives. Can we chat? – ThinkGeek Nov 26 '17 at 15:40
  • Sorry for bugging you again and again. This worked fine, but I dont want to redirect to a new URL for all the products. I have a whitelist of products like 1. dell-inspiron-15 2. dell-inspiron-16 3. dell-inspiron-17 ... for which I want to redirect to the new URL, for other products I want to use the current path itself. For example: somedomain.com/loadproduct?product=dell-inspiron-15 -> redirect to someotherdomain.com/dell-inspiron-15 somedomain.com/loadproduct?product=hp-15-abcd -> do not redirect How can I do this redirection selectively? Leads here is appreciated. – ThinkGeek Nov 29 '17 at 07:30
  • Logged another question https://stackoverflow.com/questions/47547418/selectively-redirect-to-a-new-domain-using-apache-vhost-configuration with the requirement. Please check if you have some free time. Thanks! – ThinkGeek Nov 29 '17 at 07:41