i have some links on my website with page version and i want visitors redirected to the same page but without version number.
example:
domain.com/folder/locatedpage?v=1
domain.com/folder/locatedpage?v=2
domain.com/folder/locatedpage?v=3
i need any visitor open links like this should be redirected to:
domain.com/folder/locatedpage
Wihout ?v=1
So if i share a line with ?v=1 it automatically will redirect the visitor to the URL with out ?v=1
I tried many solutions here but it didn't work for me. Thank you
CodePudding user response:
You could remove a 'v' argument from an individual page by having something like the below in the code, does that do what you are looking for?
<script>
var url = new URL(location);
url.searchParams.delete('v');
history.replaceState(null, null, url);
</script>
CodePudding user response:
This should do what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^v=\d $
RewriteRule ^ %{REQUEST_URI} [QSD,R=301,L]
You may have to add additional conditions though, other logic might get broken. This obviously depends on your setup we do not know.