0

I am trying to edit my .htaccess file to have the following rules:

if the URL contains a src=website.com AND has a parameters city=someCityHere AND state=StateHere go to this URL passing the city and state provided

OR

if URL contains src=website.com AND has zip=zipCodeHere go to this URL passing the zip code provided

OR if the url doesn't contain src=website.com redirect to thisWebsite.com

For example the url will look like this: www.mywebsite.com/?src=website.com&city=[city]&state=[state]

or www.mywebsite.com/?src=website.com&zip=[zip]

EDIT

Here are is the logic I have but it now gives a 500 error. Note the city and state value need to be separated by an underscore in the redirect url

RewriteCond %{THE_REQUEST} /\?src=website\.com&city=([^&]+)&state=([^&\s]+) [NC]
RewriteRule ^ www.anotherwebsite.com/$1_$2? [L,R=301]

RewriteCond %{THE_REQUEST} /\?src=website\.com&zip=([^&]+) [NC]
RewriteRule ^ www.anotherwebsite.com/$1? [L,R=301]

RewriteCond %{THE_REQUEST} !/\?src=website\.com [NC]
RewriteRule ^ http://www.anotherwebsite.com [L, R=301]
unknwnlttr
  • 11
  • 5
  • `%{QUERY_STRING}` doesn't contain a question mark. I answered a similar question a few years ago, see http://stackoverflow.com/q/14307333/1741542 – Olaf Dietsche Feb 13 '17 at 07:32

1 Answers1

0

You can use the following Rule to redirect /path/?src=website.com&city=foo&state=bar to http://example.com/foo/bar

RewriteEngine on

RewriteCond %{THE_REQUEST} /\?src=website\.com&city=([^&]+)&state=([^&\s]+) [NC]
RewriteRule ^ http://example.com/%1/%2? [L,R]

And for the second url, you can write a similar rule , just adjust the pattern and target.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • I have updated my code per your example, see edit above; but, now I'm getting a 500 error. I imagine I did something wrong in the syntax? – unknwnlttr Feb 13 '17 at 20:22