Expand my Community achievements bar.

The first preview of our new Community upgrade is live - check it out now.

Dispatcher Redirect rules for landing the safe page.

Avatar

Level 1

From the Jira text:

  1. Check the Referer header

  2. If the header is:

    • missing OR

    • does not originate from our domain

  3. Redirect the user

  4. Applies only when users access the search results page directly with query parameters

  5. Implemented on the dispatcher side

So the rule must:

5 Replies

Avatar

Level 4

@sesha -

This can be handled cleanly at the Dispatcher (Apache) level using mod_rewrite.

Approach:

  • Scope strictly to /search-results.html

  • Trigger only when query parameters exist

  • Validate HTTP_REFERER

    • If missing or not from the same host, redirect

  • Redirect to the safe search page (same URL without params)

  • Keep it domain/brand agnostic with no impact on other pages

Dispatcher rule (safe for commonredirect.rules):

RewriteCond %{REQUEST_URI} ^/search-results\.html$ [NC]
RewriteCond %{QUERY_STRING} .+
RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} !^https?://%{HTTP_HOST}/ [NC]
RewriteRule ^/search-results\.html$ /search-results.html? [R=302,L]

 

Result:
Direct access like /search-results.html?q=123 redirects to /search-results.html, while normal in-site navigation continues to work.

Avatar

Level 1

@lavishvasuja , Frist of all thankyou for replying me.
I have try to update the same rules in the dispatcher and after updating this rules, the complete dispatcher goes to 503 bad request. Dispatcher is completely blocking
we have three dispatcher after updating this the dispatcher goes like down.
can you please help on this.

Avatar

Level 4

@sesha 

A 503 usually means Apache failed to evaluate the rewrite safely (not a redirect issue). Since this is in commonredirect.rules, a strict condition can break all requests.

Try this safer Dispatcher rule :

RewriteCond %{REQUEST_URI} ^/search-results\.html$ [NC]
RewriteCond %{QUERY_STRING} .+
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} !^https?://[^/]+/ [NC]
RewriteRule ^ /search-results.html? [R=302,L]

 

This drops query params only for direct hits, avoids loops, and won’t impact other pages. If it still fails, Apache error.log will point to the exact rewrite issue.

 

Avatar

Level 1

still  I'm getting like that only if i update the rules. so only thing is if I pass the search-result.html?q=1237855saa >>>> it should redirect to search-result.html page only. can you please help me on this.

 

thankyou..!

Avatar

Level 4

Hi @sesha 

Step 1: Navigate to rewrites folder

Go to: 

dispatcher/src/conf.d/rewrites/

 

Step 2: Create commonredirect.rules file

Create new file: 

commonredirect.rules

 

Step 3: Add redirect rules to commonredirect.rules

RewriteCond %{REQUEST_URI} ^/search-results\.html$
RewriteCond %{QUERY_STRING} .+
RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
RewriteRule ^(.*)$ /search-result-page? [R=302,L]

Step 4: Open rewrite.rules file

Edit: 

dispatcher/src/conf.d/rewrites/rewrite.rules

 

Step 5: Add include statement

After this line:

Include conf.d/rewrites/default_rewrite.rulesapache

Add this line:

Include conf.d/rewrites/commonredirect.rulesapache

Step 6: Update domain

In 

commonredirect.rules

, replace 

yourdomain\.com

 with your actual domain

 

Step 7: Save all files

Step 8: Deploy dispatcher configuration

Step 9: Test

  • Direct access: 

    https://yoursite.com/search-results.html?q=test
     → Should redirect

     

  • From your site: Should work normally

  • No query params: Should work normally