删除PHP文件类型扩展名 [英] Removing the PHP file type extension

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

问题描述

我在顶层.htaccess中使用它来删除* .php文件上的PHP文件扩展名。

I'm using this in my top level .htaccess to remove the PHP file type extension on my *.php files.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

但是我发现它也阻止了我的浏览器调用子目录中的index.php页面。我需要在URL中明确包含/index.php。

But I have discovered it also prevents my browser from calling the index.php page in my sub-directories. I need to include /index.php explicitly in the URL.

有没有更好的方法来删除* .php文件上的PHP文件扩展名?

Is there a better way to remove the PHP file type extension on my *.php files?

推荐答案

您要去的地方:

RewriteEngine  on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

或尝试这个。这也应该在子目录路径中工作:

or try this one. This should also work in a sub-directory path:

RewriteEngine  on
RewriteRule ^(.*)$ $1.php

或在 if子句

<IfModule mod_rewrite.c>
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

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

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