将旧的.html页面重定向到没有HTML扩展页面的新页面? [英] Redirecting old .html page to new without html extension page?
本文介绍了将旧的.html页面重定向到没有HTML扩展页面的新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的旧链接就是这样,
http://www.sitename.com/category/postname.html
现在新的链接是 $ b
http://www.sitename.com/category/postname/
我在旧链接中收到404错误,我如何将所有.html页面重定向到新的非.html页面使用.htaccess?
解决方案
在文档根目录下的htaccess文件中,将添加到 wordpress规则:
RedirectMatch 301 ^ /([^ /] +)/([^ /。] +)\.html $ / $ 1 / $ 2 /
RedirectMatch 301 ^ /([^ /] +)/([^ /] +)/([^ /。] +)\.html $ / $ 1 / $ 2 / $ 3 /
如果您需要限制主机,可以使用mod_rewrite:
pre $
RewriteCond%{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^ /] +)/([^ /。] + )\.html $ / $ 1 / $ 2 / [R = 301,L]
Rewr iteCond%{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^ /] +)/([^ /] +)/([^ /。] +)\.html $ / $ 1 / $ 2 / $ 3 / [R = 301,L]
I've just changed permalinks in my wordpress site.
And my old links were like that,
http://www.sitename.com/category/postname.html
Now new links are
http://www.sitename.com/category/postname/
I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?
解决方案
In the htaccess file in your document root, add these before your wordpress rules:
RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/
Of if you need to limit it by hosts, you can use mod_rewrite:
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L]
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
这篇关于将旧的.html页面重定向到没有HTML扩展页面的新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文