Metatags For Dynamic Search Results Pages

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Metatags For Dynamic Search Results Pages

Post by MaryP » Tue Sep 08, 2015 5:25 am

Where can we put the <noindex> metatag for the dynamically-generated search results pages? Google keeps indexing our search results pages. Thank you!

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

Re: Metatags For Dynamic Search Results Pages

Post by nadeem » Tue Sep 15, 2015 2:39 am

You can add an entry to the robots.txt file (inside website root directory) to prevent search result page from indexing.

Locate the following

Code: Select all

Disallow: /BuyProduct.ashx
and replace with the below code (if your search results page becomes something like /search.aspx?k=somekeyword)

Code: Select all

Disallow: /BuyProduct.ashx
Disallow: /?k=

MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Re: Metatags For Dynamic Search Results Pages

Post by MaryP » Tue Sep 15, 2015 5:01 am

Thanks, we have tried that and it seems that more search strings keep coming up, such as /?c=, /?m=, etc. Google doesn't like seeing a large robots.txt file, so we were trying to follow Google's recommendation of adding the <noindex> metatag,

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

Re: Metatags For Dynamic Search Results Pages

Post by nadeem » Tue Sep 15, 2015 5:27 am

Ok. Then you can add the meta tag dynamically to the specific pages you don't want to index. Put the following code to the Page_Load method

Code: Select all

// ADD NOINDEX META TAG TO PREVENT BROWSERS FROM INDEXING THE PAGE
HtmlMeta keyword = new HtmlMeta();
keyword.Name = "robots";
keyword.Content = "noindex";
Page.Header.Controls.Add(keyword);
You also have to add the following using statement at the top of the page.

Code: Select all

using System.Web.UI.HtmlControls;

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Metatags For Dynamic Search Results Pages

Post by Brewhaus » Wed Sep 16, 2015 12:50 pm

Thank you for the help. As I will be the one having to input the code, please let me know if this should go into the Search.aspx / Search.aspx.cs files.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

Re: Metatags For Dynamic Search Results Pages

Post by nadeem » Wed Sep 16, 2015 10:25 pm

This will go into the search.aspx.cs file's Page_Load method. You can do something like this:

Locate

Code: Select all

BindSearchResultsPanel();
and replace with

Code: Select all

// ADD NOINDEX META TAG TO PREVENT BROWSERS FROM INDEXING THE PAGE
HtmlMeta keyword = new HtmlMeta();
keyword.Name = "robots";
keyword.Content = "noindex";
Page.Header.Controls.Add(keyword);

BindSearchResultsPanel();

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Metatags For Dynamic Search Results Pages

Post by Brewhaus » Thu Sep 17, 2015 6:10 am

Perfect. Thank you so much for your help! :D
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

Post Reply