如何使无需手动添加有路径`/一些-DIR /`或`的RewriteBase /一些-dir`此的.htaccess规则做工精细?做工、路径、精细、规则

2023-09-02 01:10:37 作者:俄﹑與悲傷冇染

我有 HTTP://localhost/some-dir/.htaccess 重写规则^(+)/ $ /一些-DIR / $ 1 [R = 301,L] 来删除网址结尾斜线。

I have http://localhost/some-dir/.htaccess RewriteRule ^(.+)/$ /some-dir/$1 [R=301,L] to remove trailing slash from URLs end.

我如何改善同认为,在 HTTP简单的.htaccess://本地主机/一些-DIR /。无需手动添加路径有htaccess的 /一些-DIR / 的RewriteBase /一些-DIR ?因此,这条规则工作正常,如果我在任何服务器路径中使用它,就像 HTTP://localhost/.htaccess 或< A HREF =HTTP://localhost/some-dir/else-path/etc/.htaccess相对=nofollow> HTTP://localhost/some-dir/else-path/etc/.htaccess 等

How can I improve the same think with simple .htaccess in http://localhost/some-dir/.htaccess without manual adding there path /some-dir/ or RewriteBase /some-dir? so that this rule works fine if I use it in any server path, like http://localhost/.htaccess or http://localhost/some-dir/else-path/etc/.htaccess etc.

推荐答案

您可以使用的 REQUEST_URI 的,而不是:

You could use REQUEST_URI instead:

RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^.+/$ %1 [R=301,L]