gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:19:35 25 4
gpt4 key购买 nike

我想知道是否可以将扩展名.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}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

关于php - 使用 .htaccess 更改 URL .php 扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31435923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com