.htaccess中 - 更换一切都结束HTML以斜线 [英] HTACCESS - Replace everything ending html with a trailing slash

查看:159
本文介绍了.htaccess中 - 更换一切都结束HTML以斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图取代一切与扩展HTML结束( 的.html )与尾部( \ )斜线即

I am trying to replace everything ending with the extension html (.html) with a trailing (\) slash i.e.

http://www.example.com/ibizaparty.html 的http:// www.example.com/ibizaparty /

http://www.example.com/ibizaparty.html to http://www.example.com/ibizaparty/

怎么可以这样使用的.htaccess即重定向/重写规则来解决?

How can this be resolved using .htaccess i.e. redirect/rewrite rules?

您的帮助是极大的AP preciated?

Your help is greatly appreciated?

推荐答案

我给你的code,但对于未来的问题,请环顾四周,搜索网站之前,请你们已经回答了数以百万计的问题次。

I'm giving you the code but for future questions please look around and search the site before you just make a question that has been answered millions of times.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

这篇关于.htaccess中 - 更换一切都结束HTML以斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆