I am using Magento version 2.2.6

I have already tried with Marketing >> URL Rewrite >> Add New URL Rewrite add custom URL but not working when we use it with question mark in URL, it's working with / (slash)

I have URL like this mydomain.com/product.asp?product=977 and I want it to be rewritten to this mydomain.com (redirect to the root of the domain)

Also, I have another example mydomain.com/catalogsearch/result/?q=lim and I want to redirect to this mydomain.com/ingpage/about-lim.html

Can anyone suggest to me how to do this via custom programming in Magento 2?

2 Answers 2


Please try this I have found that solutions.Below define in root .htaccess file inside code use it

RewriteCond %{QUERY_STRING} ^q=tank123$
RewriteRule ^(index\.php)?$ /mage229/men.html [QSD,R=301,L]

RewriteCond %{QUERY_STRING} ^color=50$
RewriteRule ^(index\.php)?$ /mage229/men/tops-men.html [QSD,R=301,L]

Locate the htaccess configuration file on web servers running the Apache Web Server software and run a command with the below syntax:

Open .htaccess in Magento 2 Root FOlder

Redirect 301 [old URL] [New URL]


Redirect 301 oldpath.html newpath.html

Notes* Make sure don't use full URL and put in last

  • I have this type of urls (many different different urls) product.asp?product=977 how to do this ? Nov 19, 2019 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.