如何使无需手动添加有路径`/一些-DIR /`或`的RewriteBase /一些-dir`此的.htaccess规则做工精细? [英] How to make this .htaccess rule work fine without manual adding there path `/some-dir/` or `RewriteBase /some-dir`?

查看:154
本文介绍了如何使无需手动添加有路径`/一些-DIR /`或`的RewriteBase /一些-dir`此的.htaccess规则做工精细?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 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]

这篇关于如何使无需手动添加有路径`/一些-DIR /`或`的RewriteBase /一些-dir`此的.htaccess规则做工精细?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆