The below weird URLs popped up on Google console...
I didnt add them and I dont know where they came from.
https://www.example.com/gallery.html?page=3https://www.example.com/gallery.html?page=2https://www.example.com/gallery.html?page=1
My 301 redirects in .htaccess are working for other pages but not these above URLs
Can anyone help me, I want to redirect them to /gallery.html
Added to my .htaccess which works for other redirects
RedirectMatch 301 /gallery.html?page=1 /gallery.html
(I assume you mean
gallery.html, as per your examples?)You can't match the query string part of the URL (everything after the first
?) using a mod_aliasRedirectMatch(orRedirect) directive. TheRedirectMatchdirective matches against the URL-path only. However, this also takes a regex, so.and?are special characters in the regex.You need to use mod_rewrite instead with an additional condition that checks the
QUERY_STRINGserver variable.To redirect
/gallery.html?page=<number>(where<number>is any sequence of digits 0-9) then you would need to do something like the following near the top of the.htaccessfile (the order of directives is important):The
$0backreference contains the entire match from theRewriteRulepattern (ie. "gallery.html").The
\d*subpattern matches digits 0-9 zero or more times.The
QSD(Query String Discard) flag is necessary to remove the query string from the redirected response.If there are any other URL parameters in the query string then the redirect will not occur (since the regex won't match).
Test first with 302 (temporary) redirect to avoid potential caching issues.
Aside:
I'm not sure exactly where you are seeing that? But that doesn't necessarily look like an "error". (Your
rel="canonical"tag appears to be correctly configured.)A Google
site:search on your domain does not return the URLs in question, only/gallery.html, so this redirect is probably not necessary.