How do I remove index.html index.php with htaccess

本秂侑毒 提交于 2019-12-25 16:54:41

问题


I have these urls in my blog

http://myblog.com/news/post1/index.php
http://myblog.com/updates/post3/index.html
http://myblog.com/index.html
http://myblog.com/blog/post4/index.php

How do I setup .htaccess so that all the urls will end with "/"

http://myblog.com/news/post1/
http://myblog.com/updates/post3/
http://myblog.com/
http://myblog.com/blog/post4/

Thanks in advance!


回答1:


To remove the .php extension from a PHP file:

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

If you want to remove the .html extension from a html file:

RewriteRule ^([^\.]+)$ $1.html [NC,L] 

Or see this post:

  • How to remove .php, .html, .htm extensions with .htaccess


来源:https://stackoverflow.com/questions/4112505/how-do-i-remove-index-html-index-php-with-htaccess

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