.htaccess中 - 更换一切都结束HTML以斜线

人气:1,019 发布:2022-09-10 标签: apache .htaccess mod-rewrite redirect regex

问题描述

我试图取代一切与扩展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]

105