/ /パスがindex.phpによって処理されるときにサブディレクトリに対して異なる404 - .htaccess、redirect、drupal、http-status-code-404、サブディレクトリ

index.php --htaccess、redirect、drupal、http-status-code-404、サブディレクトリによってパスが処理されるときのサブディレクトリの別の404

私は…したい /blog/anything-that-doesn"t-exist にリダイレクトする /blogその他の404はDrupalによって処理されます。

私のhtaccessは現在:

ErrorDocument 404 /index.php

だからすべてがDrupalによって処理されます。サブディレクトリ固有の404ルールを持つことは可能ですが、ルートディレクトリhtaccessから設定しますか?ザ /blog/ サブディレクトリはDrupalによって生成されるので、そこに優先するhtaccessを置くことはできません。

回答:

回答№1は0

Root / .htaccessファイルで次のコードを使用できます。

 RewriteEngine On


#If /blog/foo is not a directory
RewriteCond %{DOCUMENT_ROOT}/blog/$1 !-d
#And /blog/foo is not a file
RewriteCond %{DOCUMENT_ROOT}/blog/$1 !-f
#Then redirect /blog/foo to /blog
RewriteRule ^blog/(.+)$ /blog/ [NC,L,R]

それは注目に値する、実行時間RewriteRuleとErrorDocumentのディレクティブは異なります。 RewriteRuleディレクティブはErrorDocumentディレクティブの前に実行されるため、/ blog / bad_urlのリクエストは上記のルールで処理され、他の404リクエストはすべてErrorDocumentによって処理されます。