Hello, I have a multilingual site. Googlebot generates error 500 in many
case. Googlebot try any combination of parameters. It still tries to
test old urls of old websites I had in the past. To avoid this I decided
to create an if statement letting nobody enter with wrong parameters.
On one page for example I wrote this <% if params[:locale] == “en” ||
params[:locale] == “de” || params[:locale] == “fr”> (with other
parameters than en de or fr the site display itself not normally,
and with other parameters than en de fr there should be nothing to
display, as i have only a trilingual website. So if <% if
params[:locale] == “en” || params[:locale] == “de” || params[:locale] ==
“fr”, we can display the page
ELSE
I display a page with the 3 existing choices to click: fr en de. This
way I avoid a 500 error of googlebot or an anormally displayed page of a
google user clicking on a bad referenced page.
BUT the problem is that “google webmaster tools” indicates now that the
website has many errors. Because wrong parameters display a page without
error instead of returning a 404 error page. Because of this I have too
many pages to crawl, as i have infinite number of pages that returns
status 200 OK.
I just would like to write something that generates the 404 error page
status, in order googlebot do not references it.
So i copy all i found on the internet for scripts to generate a 404
error status, but nothing works.
Finally i put this html script
My app is capable to generate error status in many cases, as the page
/fr/not_found, does not exist, I get the correct error message on the
website, but for googlebot it is not a 404 status as the page exists.
How could I generate a 404 error status whenever I want and if possible
in a rhtml file?
begin
page = StaticPage.find_by_id!(53)
@text = page.text params[:locale]
rescue ActiveRecord::RecordNotFound
flash[:notice] = t :page_not_found
redirect_to index_url
end
end
I will add “response.status=404” in it.
Uh, well. That won’t work if you’re doing a redirect; “redirect” means
“send a status 302”. You can’t do both.
But what should I write in the
index.rhml in my if statement, instead of my "meta
http-equiv=“refresh”?:
That said, I don’t understand why you’re redirecting to the same page;
why not just return a “not found” response and text? Though for this
locale issue, a 406 Not Acceptable might make more sense…
Hello finally I put <%= response.status=404 %> after my if statement,
not in the controller but in the rhtml file, as I dont well know how to
deal with a controller.
the result is not bad as there is no redirect but it doesnt deliver an
true error status 404 or else, it just display 404 on the page.
Could you help me implement this correctly in the controller? Do I have
to call a special page in the controller?
Def
bla bla
end
if yes how do I execute this page, what should I write in the rhtml
statement?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.