301 重定向到新域,没有尾随/斜杠

301 redirect on new domain without trailing / slash

我想重定向来自域的所有 url:

http://exampledomain.com

到特定地址上的新域,该地址只能在地址末尾没有尾部斜杠的情况下工作

http://www.newdomain.com/123-content

我在 .htaccess 中尝试了很多规则,但每次它都重定向到 url 并在末尾添加 / 但它不起作用。

将以下规则放在旧站点主根目录的 .htaccess 中:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)([^/]+)/?$
RewriteRule ^    http://newdomain.com%1%2  [L,R=301]

注意:清除浏览器缓存再测试