删除文件扩展名的.php使用htaccess的文件文件扩展名、文件、php、htaccess

2023-09-02 09:37:05 作者:趁年轻&不如拼一拼

我想通过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]