简体   繁体   English

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

[英].htaccess remove .php but add a / at the end

I currently have some code added to my .htaccess file and it works as intended. 我目前在.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]

For example i have = http://www.hello.com/world.php 例如我有= http://www.hello.com/world.php

This code removed the php and will look like this http://www.hello.com/world 这段代码删除了php,看起来像这样http://www.hello.com/world

I want it to look like this = http://www.hello.com/world/ 我希望它看起来像这样= http://www.hello.com/world/

How do I add the / to the end? 如何在结尾加上/?

Thanks in advanced. 提前致谢。 -O -O

You can use this: 您可以使用此:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM