Forum Moderators: phranque
why this url format: https://www.example.com/?page=2835 Is going to my site's home page
RewriteCond %{QUERY_STRING} "post_type=" [NC]
RewriteCond %{QUERY_STRING} ^page=
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^page=
RewriteRule ^$ / [QSD,R=301,L]
How to redirect old urls with query string to 404 page?Without even reading the thread (although I did) the answer is simple: Do not redirect anything to the 404 page. Serving a 404 (or 410) response is not the same thing as redirecting to the 404 page, although it may look the same to a human user.
I've already tried the following:
==
RewriteCond %{QUERY_STRING} "post_type=" [NC]
# if the query string contains anything
RewriteCond %{QUERY_STRING} .
# redirect the requested path to the canonical hostname without a query string
RewriteRule (.*) https://www.example.com/$1? [R=301,L]
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{REQUEST_URI} !^/folder1/file1.*
RewriteCond %{REQUEST_URI} !^/folder2/file2.*
RewriteRule ^(.*)$ /$1? [R=301,L]