htaccess的code,除去延伸和补充+力斜线?斜线、htaccess、code

2023-09-02 09:36:20 作者:装逼遭雷劈从头劈到逼

我试图把一些htaccess的code,它会变成 example.com/filename.php 到 example.com/filename / (和力斜杠) - 我已经试过varous的方法,但每个没有工作完全正确,从500错误的子文件夹以问题与斜线,等等...

I'm trying to put together some htaccess code that will turn example.com/filename.php into example.com/filename/ (and force the slash) - I've tried varous approaches, but each hasn't worked quite right, from 500 errors on subfolders to issues with the trailing slash, etc...

请帮忙!

推荐答案

试试这个:

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

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

第一条规则重定向的请求的 /富/酒吧的.php 内外兼修 /富/酒吧 / 。第二条规则重写的请求的 /富/酒吧 / 在内部的 /富/酒吧的.php

The first rule redirects requests of /foo/bar.php externally to /foo/bar/. And the second rule rewrites requests of /foo/bar/ internally to /foo/bar.php.

和给力的结尾的斜线,试试这条规则:

And to force the trailing slash, try this rule:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]