3

最近、.htaccess を介して index.php リダイレクトをセットアップしました。ここでの考え方は、サイトに index.php と / (ホマページ) の両方がインデックスされている場合に発生する重複コンテンツの問題を無効にすることです。

これが私の元の.htaccessです

Options -Indexes
ErrorDocument 403 /customerrors/403.html
ErrorDocument 401 /customerrors/401.html
ErrorDocument 400 /customerrors/400.html
ErrorDocument 500 /customerrors/500.html
ErrorDocument 404 /customerrors/404.html

かなり基本的です。

ここにリストされている手法を使用して、index.php を / にリダイレクトしました。

http://www.askapache.com/htaccess/redirect-index-blog-root.html

それもうまくいきます。1 つの問題は、404 ページが壊れていることです。

これは、404 ページを壊している変更された .htaccess です。

RewriteEngine On
RewriteBase /
DirectoryIndex index.php
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Options -Indexes
ErrorDocument 403 /customerrors/403.html
ErrorDocument 401 /customerrors/401.html
ErrorDocument 400 /customerrors/400.html
ErrorDocument 500 /customerrors/500.html
ErrorDocument 404 /customerrors/404.html

そのため、ユーザーが 404 ページを提供する代わりに www.example.com/dafjkadbfda に入力するかアクセスすると、URL は同じ (この場合は壊れたもの) のままで、index.php ページを切断します。

これにより、ワームの別の缶が開かれます。これらの壊れたページはすべて、重複したコンテンツとメタとして表示されます。

404 ページを考慮した .htacess リダイレクトを記述する別の方法はありますか? それがここでの対立のようです。

前もって感謝します。

4

1 に答える 1

0

.htaccess のこの部分は、404 を「壊す」部分です。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

PHP スクリプトから 404 エラーを送信することで、問題を管理できます。

if ($not_a_valid_page){
    header("$_SERVER[SERVER_PROTOCOL] 404 Not Found");
    readfile("./customerrors/404.html");
    die();
}
于 2013-06-28T00:33:17.087 に答える