0
# case: leading and trailing parameters
RewriteCond %{QUERY_STRING} ^(.+)?session=[0-9a-z]+&(.+)$ [NC]
RewriteRule (.*) /$1?%1&%2 [R=301,L]

# case: leading-only, trailing-only or no additional parameters
RewriteCond %{QUERY_STRING} ^(.+)?session=[0-9a-z]+$|^osCsid=[0-9a-z]+&?(.*)$   [NC]
RewriteRule (.*) /$1?%1 [R=301,L]

URL is: https://www.test.com/test/?session=123

Shouldn't this cut off the ?session=123?

If not, how can I achieve this?

0

1 Answer 1

1

You can use this rule to remove a parameter from anywhere in the query string:

RewriteCond %{QUERY_STRING} ^(.*&)?session=[^&]*(?:&(.*))?$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [L,R=301,NE]
Sign up to request clarification or add additional context in comments.

5 Comments

Nice, works. One more thing, ist it possible to remove just if the value of session begins with "\" ? I tried: RewriteCond %{QUERY_STRING} ^(.*&)?session=[^&]*(?:&(.*))?$
Sorry didn't understand. Do you want to remove this parameter only if value starts with a double quote?
Almost. Want to remove the parameter if value starts with backslash
You can use: RewriteCond %{QUERY_STRING} ^(.*&)?session=\\[^&]*(?:&(.*))?$ [NC]
btw your question mentions session=123 which is not starting with \

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.