Sunday, April 3, 2022

[SOLVED] tricky apache rewrite configuration

Issue

I have a URL of the form

http://example.com/fetchjobs.action?jobType=crons&jobList=foo&categoryModeId=0&showOnlyLatest=true

And I want to redirect above url to url below

http://newexample.com/crons?jobList=foo&categoryModeId=0&showOnlyLatest=true

Note:

  1. domain got changed from example.com to newexample.com.

  2. Value of "jobType" is in a URL path now instead of query param. (jobType=crons vs /crons?)

  3. All other query parameters are retained as query params in a new URL.

  4. There can be any number of query parameters in source URL.

Leads here is appreciated.


Solution

Try this :

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)?jobType\=([^\&]+)&?(.*)?$
RewriteRule ^     http://newsite.com/%2??%1%3  [L,R=301,NE]    

Note: clear browser cache the test it .



Answered By - Mohammed Elhag
Answer Checked By - David Marino (WPSolving Volunteer)