Search code examples
.htaccessmod-rewrite

Redirect URLs with page version to URL without version


I have some links on my website with page version and i want visitors redirected to the same page but without version number.

example:

example.com/folder/locatedpage?v=1
example.com/folder/locatedpage?v=2
example.com/folder/locatedpage?v=3

i need any visitor open links like this should be redirected to:

example.com/folder/locatedpage

Without ?v=1

So if i share a line with ?v=1 it automatically will redirect the visitor to the URL without ?v=1

I tried many solutions here but it didn't work for me.


Solution

  • 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.