0

could you help me get this working please.

I am trying to redirect

/search.php?id=5GHU&distance=50&sort=title

or

/search.php?id=5GHU

or

/search.php?id=5GHU&distance=50

to

/search/?query_string_values

i.e. whether it's one query string parameter or many they all should go there

This is what I tried.

RewriteBase /

RewriteCond %{QUERY_STRING} (?:^|&)id=([^&]+)
RewriteRule ^search\.php$ /search/%1? [L,R=permanent]

Thanks

0

1 Answer 1

1

Sorry for my confusion about your question, I got it now. So...

Modify your .htaccess like this:

RewriteEngine On
RewriteRule "^/search.php$"    "/search/"    [L,R=301,QSA]

In short it will take the query string (what follows /search.php that starts with ?) and append it to "/search/". That is done by the QSA flag to RewriteRule. No matter how many parameters you have, it will append it all.

See https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa

So

/search.php?a=1&b=2  -->    /search/?a=1&b=2
/search.php?c=3      -->    /search/?c=3

Since /search/?a=1&b=2 does not specify a page to use, it will use the default page defined by DirectoryIndex in your configuration. I prefer to explicitly specify the page, but it works without.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - let me check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.