将 URI 中的部分文件名替换为 htaccess mod_rewrite所需的 x 域解决方案


Replace part of filename in URI with htaccess mod_rewrite x-domain solution required

我一直在搜索htaccess上的教程,但是每个示例似乎在重写的第二部分中都有一个绝对的URL。我的网站跨多个域交付,因此我需要 x 域解决方案。

规则应声明以下内容:所有确实转到确认.php文件的文件现在都转到确认/文件夹。 所以...

http://example.com/confirm.php?token=32879 现在应该去 http://example.com/confirm/?token=32879

http://elpmaxe.com/confirm.php?token=32879 现在应该去 http://elpmaxe.com/confirm/?token=32879

我想出的代码是:

RewriteCond %{REQUEST_URI} confirm.php$ [NC]
RewriteRule ^(confirm'.php)$ confirm/ [L,R=301]

但这会将整个文档根路径追加到 URL 的末尾,如下所示:

http://example.local/var/www/vhosts/example.co.uk/confirm/?t=CB3Qj&e=578

请帮忙!

此规则应该有效:

RewriteEngine On
RewriteRule ^(confirm'.php)$ /confirm/ [L,R=301,NC]

确保在新浏览器中进行测试,以避免 301 缓存问题。