I am trying to write some search engine optimized code for a Coldfusion project, and one thing I am trying to 开发者_开发知识库accomplish in that is changing a few page variables when the page is referred from different search engines.
Does anyone know if there is a way, or if it's even possible to mock the CGI.HTTP_REFERER to Google, Bing, Yahoo, etc??
Refactor your method, instead of using CGI scope directly, use an argument, e.g.:
<cfargument name="cgiScope" type="struct" default="#CGI#" require="false">
Done. :)
It is frowned upon to show different kind of content for search engine bots. Either way, it is not possible to change the CGI.HTTP_REFERER with Coldfusion. Your best bet is to edit your "hosts" file and add an entry to point google.com to the IP of your server (eg. 127.0.0.1) and set up a page with a link to your site to fake the request as coming from Google/Bing/Yahoo.
The value of the CGI scope is large in part determined by what's sent in a request's headers. The referer in particular is easily spoofed. See the following:
- Ben Nadel explains how to with CFHTTP and CFHTTPPARAM to spoof the referer.
- Firefox Plugin Modify Headers (my comment points an answer with this).
I would make a function getHttpReferer that normally returns CGI.HTTP_REFERER, however when you unit test you can mock out that function to return whatever you want.
精彩评论