2

質問が単純であるため、宝石の使用を避けようとしています。

私のウェブサイトには次の ?params= があります

"type" just filters by type. if this isnt specified they're all lumped together
"sort" sorts by date/whats hot/latest
"view" changes compact view/list view
"scroll" isnt even used yet, its for infinite scroll on or off which i havent put in yet
"reset" is a link when you click the logo (not the home link) that resets all session params to "all" and "whats hot" (the default)
"page" is the pagination which i think is the only really important one

?page=いくつかの助けを得た後、ページネーションを除いて、すべてのコンテンツにクエリパラメーターなしでアクセスできるため、唯一の本当に重要なものであると通知されました。

だから今私はこれを持っています:

  <link rel="canonical" href="<%= "http://#{request.host + request.fullpath}" %>">

だから私の質問は、これを変更してURLのみを配置し、存在する場合は ?page= を配置するが、他のすべてのパラメーターを無視するようにするにはどうすればよいですか?

4

3 に答える 3

5

これはうまくいかないようです

<link rel="canonical" href="<%= "http://#{request.host + url_for(:page => params[:page]) }" %>">

于 2012-08-13T16:58:21.693 に答える
0

動作する最も単純なケースでは:

<link rel="canonical" href="<%= "#{request.protocol}#{request.host}#{request.path}" %>">

プロトコルを使用している場合、または正規 URL で GET パラメータを使用する場合は、忘れずに追加してください。

于 2018-04-25T17:14:20.383 に答える