删除文件扩展名的.php使用htaccess的文件 [英] Remove the file extension .php using htaccess file

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

问题描述

我想通过htaccess文件中删除从URL中的.php。例如home.php回家 我使用htaccess的文件中的以下重写规则。

I want to remove the .php from the url through htaccess file. for example home.php to home I'm using the following rewrite rule in htaccess file.

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

我也想分配登录为指标。 我怎样才能改变它。

I also want to assign the login as index. How can I change it.

推荐答案

这是在code,你可以用它来隐藏PHP扩展:

This is the code you can use to hide .php extension:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L,NC]

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

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