mirror of
https://github.com/szepeviktor/wordpress-website-lifecycle.git
synced 2026-07-27 02:55:34 +08:00
* Implement trailing slash for no-dot paths Adds a filter to mod_rewrite_rules to enforce trailing slashes for URLs without dots. * Clarify conditions for trailing slash in comment Update comment to clarify conditions for adding trailing slash. * Update _core-auto-trailing-slash.php
25 lines
634 B
PHP
25 lines
634 B
PHP
<?php
|
|
|
|
/*
|
|
* Plugin Name: Trailing slash for no-dot paths
|
|
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
|
|
*/
|
|
|
|
add_filter(
|
|
'mod_rewrite_rules',
|
|
static function ($rules) {
|
|
$insertion = <<<HTACCESS
|
|
# Add trailing slash if URL doesn't contain a dot and doesn't already end with /
|
|
RewriteCond %{REQUEST_URI} !(\.|/$)
|
|
RewriteRule ^(.+)$ /$1/ [R=301,L]
|
|
|
|
HTACCESS;
|
|
$needle = "RewriteEngine On\n";
|
|
if (strpos($rules, $needle) === false) {
|
|
return $needle.$insertion.$rules;
|
|
}
|
|
return str_replace($needle, $needle.$insertion, $rules);
|
|
},
|
|
20,
|
|
1
|
|
);
|