Reputation: 125
First, let me start by saying I'm not very skilled with .htaccess. I did search through StackOverflow and found many redirect examples, but couldn't find one to do what I'm trying to accomplish.
I'm trying to redirect specific URLs with query strings to a different URL with a query string. The query string values are dynamic.
For example, I'd like to redirect this:
https://www.example.com/page/?search=search_string¶m1=whatever¶m2=whatever
To this:
https://www.example.com/?s=search_string
In the first URL, I don't care about any parameters except for the 'search' value. The value for 'search' in the first URL will be the value of 's' in the second URL. I want to drop all other parameters. Keep in mind that the value for 'search' in the first URL is dynamic.
I tried the following with no luck:
RedirectMatch 301 ^/page/?(.*)$ https://www.example.com/?$1
Upvotes: 0
Views: 1794
Reputation: 784958
You will need to use mod_rewrite
here to be able to examine and capture values from QUERY_STRING
.
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)search=([^&]+) [NC]
RewriteRule ^page/?$ /?s=%1 [L,NC,R=302]
Upvotes: 1