使用 .htaccess 更改 URL .php 扩展名

Change URL .php extension using .htaccess

我想知道是否可以将扩展名 .php 更改为“/”。

示例:

http://localhost/website/example.php?id=19

转换成,

http://localhost/website/example/?id=19

或者如果你们对地址有更好的想法,我想知道我应该使用什么。

我是清洁 URL 的初学者。

凹陷。

您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此代码:

RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,NE,L]

# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/\.php -f [NC]
RewriteRule ^(.+?)/?$ .php [L]