使用.htaccess从网址中删除.php扩展名? [英] Removing .php extension from URLs using .htaccess?

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

问题描述

是否可以使用 .htaccess 文件从我的所有URL中删除.php部分?

Is it possible to remove the .php part from all of my URLs using a .htaccess file?

两个示例:

http://url.com/home.php
http://url.com/shops.php

成为:

http://url.com/home/
http://url.com/shops/

所有帮助将不胜感激。

推荐答案

这应该有效:

RewriteEngine On
RewriteRule \/([^\/]+)\/$ $1.php

它将为您提供以url的最后一段命名的文件:

It will serve you the file named after the last segment of the url:

http://example.com/shops/shopname1/ -> shopname1.php

http://example.com/shops/shopname1/ -> shopname1.php

http://example.com/shops/ -> shop.php

http://example.com/shops/ -> shops.php

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

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