最近、末尾のスラッシュを削除するために、.htaccess に以下を追加しました。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
また、CI_URI を拡張して、許可されていない URI 文字を削除し、404 ページにリダイレクトします (私ではなく、元の作成者に感謝します!):
public function _filter_uri($str)
{
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str))
{
show_404(); //show 404 error page instead "The URI you submitted has disallowed characters" error
}
}
// Convert programatic characters to entities and return
return str_replace(
array('$', '(', ')', '%28', '%29'),
// Bad
array('$', '(', ')', '(', ')'),
// Good
$str);
}
}
.htaccess コードを追加したので、URI に許可されていない文字 (たとえば、http ://www.mysite.com/contro,ller/func,tion (コンマ付き)) があると、301 ページにリダイレクトされ、その後に次のリンクが表示されます。 404 エラー ページ (つまり、「ページはここに移動しました」と、標準の 404 ページへのリンクが表示されます)。
許可されていない文字が標準の 404 ページにリダイレクトされるように、両方を連携させることはできますか?