Forum Moderators: phranque
Modifying the Query String
By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.
[edited by: phranque at 11:08 pm (utc) on Nov 12, 2018]
[edited by: phranque at 5:00 am (utc) on Nov 13, 2018]
[edit reason] unlinked urls [/edit]
RewriteCond %{QUERY_STRING} language=en
RewriteRule ^(\d+\.html) https://www.example.com/$1? [R=301,L]
or RewriteCond %{QUERY_STRING} language
RewriteRule ^(\w+\.html) https://www.example.com/$1? [R=301,L]
or RewriteCond %{QUERY_STRING} .
RewriteRule ^([^.]+\.html) https://www.example.com/$1? [R=301,L]
et cetera, where you pick one from Column A and another from Column B: %{QUERY_STRING} ^language=en$
means the query string can consist only of this exact parameter-and-value set %{QUERY_STRING} language=en
without ^ $ anchors means that "language=en" can occur anywhere in the query string, but the other stuff can be thrown away too %{QUERY_STRING} language
means that you don't care what value the "language" parameter has, because you're getting rid of everything. And finally %{QUERY_STRING} .
means that you don't care what the query string says at all: if it's present, get rid of it. https://www.example.com/$1?
means "keep the same URLpath, but get rid of any and all query strings”. [edited by: phranque at 7:38 pm (utc) on Nov 13, 2018]
[edit reason] typo: \1 vs $1 [/edit]
RewriteRule ^(.*)/index.php$ https://www.example.com/$1/? [R=301,L]
RewriteCond %{QUERY_STRING} language=en
RewriteRule ^(\w+\.html) https://www.example.com/$1? [R=301,L]
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] [edited by: phranque at 7:42 pm (utc) on Nov 13, 2018]
RewriteCond %{QUERY_STRING} .
RewriteRule ^(\d+\.html) https://www.example.com/$1? [R=301,L]
where that lone . in the Condition means "any content at all". It means the server only has to check for the existence of any character, instead of matching all eleven bytes of "language=en". And then the ? in the target means "get rid of it all".
its actualy alphacharacters and numerals.Well, now you say so. Yes, in that case use \w instead of \d.