0

Is there a way to detect if a URL contains a Super Search query?

I have a template that displays super search results, but analytics are also showing a bunch of non-existent URLs showing up in the same template group and I'd like to be able to detect if a URL contains a search query and if it doesn't, redirect to the 404 template.

Examples:

site.com/tours/made-up – bad
site.com/tours/search&keywords=island – good

I'm also having trouble with URLs that contain super search queries and gclid querystrings and pagination. There's a stable of sites that are very similar. On one site, this works fine:

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /

# Redirect index.php Requests
  RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
  RewriteCond %{THE_REQUEST} ^GET
  RewriteRule ^index\.php(.+) $1 [R=301,L]

# Force the www
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

# HTTPS Redirects
  RewriteCond %{SERVER_PORT} 80
  RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]

# Add a trailing slash to paths without an extension
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ /$1/ [R=301,L]

# Standard ExpressionEngine Rewrite
  RewriteCond %{REQUEST_URI} ^/
  RewriteCond %{QUERY_STRING} ^(gclid=.*)
  RewriteRule ^(.+) /index.php?/ [L,PT]
  RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond  $1 !^(themes|index\.php|admin\.php|favicon\.ico|index\.php|path\.php|php\.ini) [NC]
  RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>

i.e., when you click on a pagination link, it removes the gclid querystring and adds PXX to the URL and you get the updated results.

But on other sites with the exact same rules in place, the PXX just gets added after the gclid querystring and you still get the same first page of results.

Anyone know why that might be? Or have a foolproof method for this scenario?

  • What renders at site.com/tours/made-up? A search result page? You can probably use template routes to fix this issue (the first issue, not the second). – jrothafer Jul 1 '16 at 13:07
  • Yeah /tours/made-up is the same as /tours/. Do you have an example of how template routes would help? – Tyssen Jul 1 '16 at 21:30
1

Something you could do inside the Results template is make a conditional dependent on there being a keyword and/or custom field search. And if not, redirect the user:

{if super_search_keywords}
{if:else}
{redirect="good/bye"}
{/if}

OR

{if super_search_my_custom_field}
{if:else}
{redirect="good/bye"}
{/if}

OR

{if super_search_keywords AND super_search_my_custom_field}
{if:else}
{redirect="good/bye"}
{/if}

All of these searches check to see if the corresponding field(s) exist as queries in the URL. :)

| improve this answer | |
  • Thanks, I think this solves the first issue. Now if I could just figure out why pagination breaks with gclid querystrings on one site and not others… – Tyssen Jul 7 '16 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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