删除.html扩展后添加尾部斜杠

时间:2016-07-18 22:31:28

标签: html wordpress apache .htaccess mod-rewrite

我的网站非www wordpress在子目录中有一些静态网页 root 其他子目录

  1. 我想从根目录中的网页中删除.html扩展名 子目录中的其他静态网页。
  2. 在最后添加斜杠。
  3. 301使用斜杠从非斜杠重定向到url。
  4. 所以它应该是

    http://domain.com/articles.htmlhttp://domain.com/articles/

    http://domain.com/subdirectory/book.htmlhttp://domain.com/subdirectory/book/

    以下代码

    1. 最后使用非斜杠
    2. 将带有斜杠的301网址重定向到非
    3. 这是我的.htaccess

       <IfModule mod_rewrite.c>     
       Options +FollowSymLinks -MultiViews
      
      
      RewriteEngine On     
      RewriteBase /
      
      #removing trailing slash
      RewriteCond %{REQUEST_FILENAME} !-d    
      RewriteRule ^(.*)/$ $1 [R=301,L]
      
      #www to non
      RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC]
      RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
      
      #html
      RewriteCond %{REQUEST_FILENAME} !-f     
      RewriteCond %{REQUEST_FILENAME} !-d    
      RewriteRule ^([^\.]+)$ $1.html [NC,L]
      
      #index redirect 
      RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/     
      RewriteRule ^index\.html$ http://domain.com/ [R=301,L]
      RewriteCond %{THE_REQUEST} \.html     
      RewriteRule ^(.*)\.html$ /$1 [R=301,L] 
      </IfModule>
      

      PS一切都可以使用wordpress,只有静态页面的问题。

      先谢谢

0 个答案:

没有答案
相关问题