admin管理员组文章数量:1130349
I recently changed the permalink structure on my 2-month-old blog to a user friendly one which means a whole bunch of 404s. I wish to redirect the following:
.html
to
/
Before coming here, I spent days looking for this redirect online but never found. The redirect plugins recommended don't work. I just need a .htaccess rule to fix this.
I recently changed the permalink structure on my 2-month-old blog to a user friendly one which means a whole bunch of 404s. I wish to redirect the following:
https://example/poastname.html
to
https://example/postname/
Before coming here, I spent days looking for this redirect online but never found. The redirect plugins recommended don't work. I just need a .htaccess rule to fix this.
2 Answers
Reset to default 0Try adding this code to .htaccess:
RedirectMatch 404 /\d{4}/\d{2}/\d{2}/(.*)\.html http://example/$1
It should fix the issue.
You would need to do something like the following at the top of your .htaccess file, before the existing front-controller (ie. before # BEGIN WordPress).
RewriteRule ^([\w-]+)\.html$ /$1/ [R=302,L]
This assumes your "postname" consists of just the characters a-z, A-Z, 0-9, _ and -.
The RewriteRule pattern captures the postname before the .html URL suffix and saves this in the $1 backreference, which is used in the substitution string (2nd argument).
Note that this is a 302 (temporary) redirect. Only change it to 301 (permanent) when you are sure it's work OK, in order to avoid any potential caching issues. As always, clear your browser cache before testing.
You should use mod_rewrite (as opposed to mod_alias Redirect or RedirectMatch) in order to avoid conflicts with existing mod_rewrite directives. mod_rewrite executes before mod_alias, despite the apparent order of the directives in the config file.
I recently changed the permalink structure on my 2-month-old blog to a user friendly one which means a whole bunch of 404s. I wish to redirect the following:
.html
to
/
Before coming here, I spent days looking for this redirect online but never found. The redirect plugins recommended don't work. I just need a .htaccess rule to fix this.
I recently changed the permalink structure on my 2-month-old blog to a user friendly one which means a whole bunch of 404s. I wish to redirect the following:
https://example/poastname.html
to
https://example/postname/
Before coming here, I spent days looking for this redirect online but never found. The redirect plugins recommended don't work. I just need a .htaccess rule to fix this.
2 Answers
Reset to default 0Try adding this code to .htaccess:
RedirectMatch 404 /\d{4}/\d{2}/\d{2}/(.*)\.html http://example/$1
It should fix the issue.
You would need to do something like the following at the top of your .htaccess file, before the existing front-controller (ie. before # BEGIN WordPress).
RewriteRule ^([\w-]+)\.html$ /$1/ [R=302,L]
This assumes your "postname" consists of just the characters a-z, A-Z, 0-9, _ and -.
The RewriteRule pattern captures the postname before the .html URL suffix and saves this in the $1 backreference, which is used in the substitution string (2nd argument).
Note that this is a 302 (temporary) redirect. Only change it to 301 (permanent) when you are sure it's work OK, in order to avoid any potential caching issues. As always, clear your browser cache before testing.
You should use mod_rewrite (as opposed to mod_alias Redirect or RedirectMatch) in order to avoid conflicts with existing mod_rewrite directives. mod_rewrite executes before mod_alias, despite the apparent order of the directives in the config file.
本文标签: redirectRedirecting old permalink structure to new in htaccess
版权声明:本文标题:redirect - Redirecting old permalink structure to new in htaccess 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749093042a2314819.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论