2

How can I disable advanced search feature in Magento?

Even you remove the links from frontend using layouts, if someone who knows Magento URL's accesses /catalogsearch/advanced will get the Advanced Search page.

I discovered some visitors are accessing catalogsearch/advanced/ directly. Why they are doing this? I found that using Advanced Search feature can provide to your competition, very easy and fast, information about how many products you have enabled from each brand/category/in total.

For example in Advanced Search just search for price between 0 and 1000000 and you will get for sure all products as number. Search for all manufacturers and you will get the number of all products in your store too. In my opinion this should be protected. In this case Advanced Search feature should be used but with precaution.

Back to main question how to Enable/Disable Advanced Search for the issue I mentioned above. First I was thinking to rewrite a rule for /catalogsearch/avanced link. The redirect page could have a pretty nice banner.

Thank you.

2
  • I appreciate for your replies. I am using now Nginx proxy server (very intuitive) in front of Apache. I could go with Pound (SSL) + Varnish + Nginx, but I wanted to continue using Virtualmin/Webmin. In my Nginx file configuration I am using something very simple. location /magento_root/catalogsearch/advanced/ { return 444; } If someone will try accessing by URL the Advanced Search link he will get a nice error!
    – ADDISON74
    Commented Nov 20, 2014 at 18:53
  • I will use .htaccess to deny the link to Advanced Search. If it is included in URL the visitor will get a 404. Thank you all for your help.
    – ADDISON74
    Commented Apr 28, 2015 at 5:43

6 Answers 6

3

If you want to remove the links you can via the Layout XML:

<layout version="0.1.0">
    <default>
        <reference name="footer_links">
             <!-- Remove 'Advanced Search' -->
            <action method="removeLinkByUrl"><url helper="catalogsearch/getAdvancedSearchUrl" /></action>
    </reference>
 </default>
</layout>

To disable the controller itself (while not the cleanest approach is the quickest) create a copy of:

app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php

Into the local code pool app/code/local/Mage/CatalogSearch/controllers/AdvancedController.php

And overwrite the local copy to:

class Mage_CatalogSearch_AdvancedController extends Mage_Core_Controller_Front_Action
{

    public function indexAction()
    {
         $this->_redirectUrl('/');
    }

    public function resultAction()
    {
         $this->_redirectUrl('/');
    }
}

Any requests will be redirected to home.

2

Since URL rewrite does not work for result page (same for disabling module output), here another more flexible solution:

Solution 1:

Create an extension to redirect users to configured "CMS No Route Page".

  1. listen to two events:

    • controller_action_predispatch_catalogsearch_advanced_index
    • controller_action_predispatch_catalogsearch_advanced_result
  2. add an observer

    public function disableAdvancedSearch(Varien_Event_Observer $observer)
    {
        if (!Mage::getStoreConfigFlag('catalog/search/enable_advanced_search')) {
            $path = Mage::getStoreConfig('web/default/cms_no_route');
            $observer->getControllerAction()->getResponse()->setRedirect(Mage::getUrl($path));
        }
    }
    
  3. add config section

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <sections>
            <catalog>
                <groups>
                    <search>
                        <fields>
                            <enable_advanced_search translate="label">
                                <label>Enable Advanced Search</label>
                                <frontend_type>select</frontend_type>
                                <source_model>adminhtml/system_config_source_enabledisable</source_model>
                                <sort_order>999</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>
                            </enable_advanced_search>
                        </fields>
                    </search>
                </groups>
            </catalog>
        </sections>
    </config>
    

M1: https://github.com/sreichel/magento-StackExchange_DisableAdvancedSearch
M2: https://github.com/sreichel/magento2-StackExchange_DisableAdvancedSearch

Solution 2:

Add this (or something better) to .htaccess ...

RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^catalogsearch/advanced/(.*)$ /no-route [R=301,L]
2
  • This is an old question but I appreciate for your post. Personally I implemented Solution 2 in .htaccess file, using RedirectMatch directive for the following paths: /downloader, /catalogsearch/term/popular, /catalog/seo_sitemap/product, /catalog/seo_sitemap/category, /rss/catalog/notifystock, /rss/order/new, /index.phprss/catalog/notifystock. All paths are redirected to 404.php.
    – ADDISON74
    Commented Jul 23, 2017 at 17:25
  • @ADDISON74 just search a storeview scope based solution, maybe editable from backend, so came up with this and just posted it :)
    – sv3n
    Commented Jul 24, 2017 at 12:14
0

Yes you are right, you can use a rewrite option because Magento has catalogSearch module for search functionality if we will disable that extension then it will stop simple search as well.

There is one more option which you can use, you can override Advance catalog search template file which location is following:- base/default/template/catalogsearch/advance/form.phtml file, you can put this file with same folder structure with a different design into your theme folder. So you can remove search form from there and can use a different design.

0

I think instead of rewriting the controller you can use Magento's URL Redirect Management feature

i.e in Admin go to

Catalog>Url Redirects > Add URL redirect> Select URL redirect Type to "Custom"

Choose Store, Request Path: catalogsearch/advanced/ Target Path: Any page line no-route or home page Redirect Type: Permanent (301) "So that crawlers will crawl target path instead of advance search url"

0

If you are on Apache you can do this with redirects. Basic search will still work, but the catalogsearch page (and everything below it) will just go to the home page. The search terms will still be in the URL, but they will of course be ignored.

To your httpd.conf file add the following:

Redirect "/catalogsearch/advanced/result/" "/"
Redirect "/catalogsearch/advanced/"        "/"
Redirect "/catalogsearch/result/"          "/"
Redirect "/catalogsearch/"                 "/"

(You can replace "/" with anything you want).

-1

IN Magento 2.1, you can disable the search module from the backend: go to STORES >> CONFIGURATION >> ADVANCED >> ADVANCED >> Disable Modules Output scroll to Magento_Search and/or Magento_CatalogSearch and disable it then save. Thereafter remember to clear the cache.

1
  • This disables simple search as well, which is not intended.
    – Erfan
    Commented Jul 24, 2017 at 4:00

Your Answer

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

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