从 url 中删除 .php 扩展名 [英] Remove .php extension from url

查看:49
本文介绍了从 url 中删除 .php 扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过重写 url 从 url 中删除 .php 扩展名和查询字符串我知道这可以在 .htaccess 文件中完成到目前为止,我的 .htaccess 文件中有这个

I am required to remove .php extension and query string as well from url by rewriting the url I know this can be done in .htaccess file I have this in my .htaccess file so far

            RewriteEngine on
            DirectoryIndex Home.html

            RewriteCond %{REQUEST_FILENAME}.php -f
            RewriteCond %{REQUEST_URI} !/$
            RewriteRule (.*) $1.php [L]

            # if a directory or a file exists, use it directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            # otherwise forward it to index.html
            RewriteRule .* Home.html

现在是网址example.com/blog.php?post=12&comment=3可以通过example.com/blog.php/post/12/comment/3但我也想删除 .php 扩展名这必须可以通过这个网址访问example.com/blog/post/13/comment/3

now the url example.com/blog.php?post=12&comment=3 can be accessed by example.com/blog.php/post/12/comment/3 but i want to remove .php extension as well this must be accessible through this url example.com/blog/post/13/comment/3

有什么帮助吗?

提前致谢.

推荐答案

搜索除之外的所有内容. /

RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

这篇关于从 url 中删除 .php 扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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