Redirecting old .html page to new without html extension page?

前端 未结 2 515
忘掉有多难
忘掉有多难 2021-01-13 14:00

I\'ve just changed permalinks in my wordpress site.

And my old links were like that,

http://www.sitename.com/category/postname.html

相关标签:
2条回答
  • 2021-01-13 14:55

    In the htaccess file, just put:

    Redirect 301  /postname.html  http://www.sitename.com/category/postname/
    
    0 讨论(0)
  • 2021-01-13 14:58

    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]
    
    0 讨论(0)
提交回复
热议问题