Page 1 of 1
Metatags For Dynamic Search Results Pages
Posted: Tue Sep 08, 2015 5:25 am
by MaryP
Where can we put the <noindex> metatag for the dynamically-generated search results pages? Google keeps indexing our search results pages. Thank you!
Re: Metatags For Dynamic Search Results Pages
Posted: Tue Sep 15, 2015 2:39 am
by nadeem
You can add an entry to the
robots.txt file (inside website root directory) to prevent search result page from indexing.
Locate the following
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=
Re: Metatags For Dynamic Search Results Pages
Posted: Tue Sep 15, 2015 5:01 am
by MaryP
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,
Re: Metatags For Dynamic Search Results Pages
Posted: Tue Sep 15, 2015 5:27 am
by nadeem
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.
Re: Metatags For Dynamic Search Results Pages
Posted: Wed Sep 16, 2015 12:50 pm
by Brewhaus
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.
Re: Metatags For Dynamic Search Results Pages
Posted: Wed Sep 16, 2015 10:25 pm
by nadeem
This will go into the search.aspx.cs file's Page_Load method. You can do something like this:
Locate
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();
Re: Metatags For Dynamic Search Results Pages
Posted: Thu Sep 17, 2015 6:10 am
by Brewhaus
Perfect. Thank you so much for your help!
