应该是个相当简单的程序。我已经完成了相当一部分的互联网搜索,无法让htaccess重写在/public_html中工作
使用VPS Apache服务器,知道为什么吗?提前谢谢你!
尝试旧的RedirectMatch 301和mod_rewrite RewriteRuleas (每次一个)如下:
# New Post URLs, without dates, requires redirects for old links.
RedirectMatch 301 ^/([0-9]+)/([0-9]+)/(?!page/)(.+)$ https://www.url.org/$3
# or RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(?!page/)(.+)$ https://www.url.org/$3
BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})/([0-9]{2})/([a-z0-9\-/]+)$ /$3 [R=301,NC,L]
etc...发布于 2018-04-25 18:24:39
实际上,您可以在Settings -> Permalinks中更改它们,它将更改为post生成的链接。如果您仍然对结果不满意,可以使用WordPress过滤器删除date_rewrite_rules重写日期的规则。
更新:
在这种情况下,您可以使用post_rewrite_rules使发布规则的日期保持工作状态,并在tempalte_redirect操作钩子期间实现重定向。您可以将此代码插入到代码库中,并在WordPress中刷新重写规则。在那之后就能工作了。
add_filter( 'post_rewrite_rules', function( $rules ) {
global $wp_rewrite;
$rule = [ '([0-9]{4})/([0-9]{1,2})/([^/]+)(?:/([0-9]+))?/? =>
'index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]' ];
return array_merge($rules, $rule);
});
add_filter('template_redirect', function(){
global $wp_query;
if ( ! is_single() ) {
return;
}
if ( $wp_query->get('monthnum') !== "" && $wp_query->get('year') !== "" ) {
wp_redirect( get_permalink(), 301 );
}
});https://wordpress.stackexchange.com/questions/301854
复制相似问题