Googleに存在しないクエリーの付いたurlがクロールされて困っております。存在しないurlについては404を返したいと思います。
サイトは以下の2ページが存在します。
http://example.com
http://example.com/index.html(上のパターンにリダイレクトでも可)
http://example.com/hoge.html
今回404を返したいurlパターンです。
http://example.com/?
http://example.com/?foo
http://example.com/?foo=bar
http://example.com/?foo=bar&foo1=bar1&(この後もいろいろ続く)
http://example.com/?&foo
hoge.htmlの場合
http://example.com/hoge.html?
http://example.com/hoge.html?foo
http://example.com/hoge.html?foo=bar
http://example.com/hoge.html?foo=bar&foo1=bar1&(この後もいろいろ続く)
http://example.com/hoge.html?&foo
自分でも設定してみたのですが、いくつか404が出せず困っております。
上記のパターンで404が返せる具体的なhtaccessを教えていただけないでしょうか?
自分で設定したhtaccessも置いておきます。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*=
RewriteRule ^$ /? [R=404,L]
</IfModule>
とにかく URL 中に? が含まれていたら 404 を返すには以下のようにやります。
RewriteCond %{REQUEST_URI} \? RewriteRule ^ - [R=404,L]
設定によっては.htacessの更新が必要です。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
http://www.cquery.net/modrewrite_parmlink_404.html