Remove everything after the question mark in the URL?

Remove everything after the question mark in the URL? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Remove everything after the question mark in the URL? error on your web browser. Problem :


Is there any way to redirect a page with a question mark in the URL, to the same page, but with everything after the question mark removed?



For example:



From: /residential-properties/projectname/?utm_source=moneycontrol&utm_medium=email&utm_campaign=project



To: /residential-properties/projectname/



I hope you get my question.


Solution :

A literal question mark in the URL marks the start of the query string, so you can test if the query string contains anything and redirect if it does. Using Apache mod_rewrite in .htaccess:



RewriteEngine On
RewriteCond %QUERY_STRING .
RewriteRule (.*) /$1? [R=301,L]


The RewriteRule pattern matches against the URL-path, which notably excludes the query string.



The ? (question mark) on the end of the RewriteRule substitution effectively removes the query string from the rewritten URL by creating an empty query string. The question mark itself does not appear in the resulting URL. If you are on Apache 2.4+ then you can use the QSD flag instead (Query String Discard).



If you only need to do this for a specific URL, then change the RewriteRule accordingly:



RewriteRule ^(residential-properties/projectname/)$ /$1? [R=301,L]


Even easier:



RewriteCond %QUERY_STRING .
RewriteRule ^ %REQUEST_URI? [R=301,L]

We hope that this article has helped you resolve the redirects, query-string, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=