HTACCESS - Replace everything ending html with a trailing slash

狂风中的少年 提交于 2019-12-25 18:49:20

问题


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

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

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

Your help is greatly appreciated?


回答1:


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]


来源:https://stackoverflow.com/questions/32166307/htaccess-replace-everything-ending-html-with-a-trailing-slash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!