.htaccess删除.php,但在末尾添加/

dsekswqp  于 2023-01-17  发布在  PHP
关注(0)|答案(1)|浏览(151)

我目前有一些代码添加到我的.htaccess文件,它按预期工作。

RewriteEngine On

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

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

例如,我有= http://www.hello.com/world.php
这段代码删除了php,看起来像http://www.hello.com/world
我希望它看起来像这样= http://www.hello.com/world/
如何在末尾添加/?

67up9zun

67up9zun1#

您可以使用以下命令:

RewriteEngine On

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

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

相关问题