gpt4 book ai didi

.htaccess - htaccess代码可删除扩展名并添加+强制尾部斜杠?

转载 作者:行者123 更新时间:2023-12-04 05:05:36 26 4
gpt4 key购买 nike

我正在尝试将一些htaccess代码放到一起,它将 example.com/filename.php 变成 example.com/filename/(并强制使用斜杠)-我尝试了多种方法,但是每种方法都没有正常工作,从子文件夹上的500错误到尾部斜杠等问题...

请帮忙!

最佳答案

试试这个:

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

RewriteRule (.*)/$ $1.php [L]

第一条规则从外部将 /foo/bar .php的请求重定向到 /foo/bar /。第二条规则在内部将 /foo/bar /的请求重写为 /foo/bar .php

为了强制在末尾加斜杠,请尝试以下规则:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]

关于.htaccess - htaccess代码可删除扩展名并添加+强制尾部斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1068595/

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