重定向(删除链接中的第一个“-”)



我现在在研究大组链接上的一组不同的重定向规则。因此,例如,如果我想在"temp"之后添加一个"-",例如:

tempfile-abc1.php > temp-file-abc1.php
tempfile-def2.php > temp-file-def2.php
tempfile-ghi3.php > temp-file-ghi3.php

我使用以下代码:

 RewriteRule ^(temp)(file-.+.php)$ /$1-$2 [L,NC,R=301]

但是我现在想做的是反转它,以便从链接中删除第一个"-"连字符。我需要 1 个规则/条件为链接集,例如:

temp-file-abc1.php > tempfile-abc1.php
temp-file-def2.php > tempfile-def2.php
temp-file-ghi3.php > tempfile-ghi3.php

我将不胜感激任何建议/解决方案。

尝试以下规则 我假设临时文件是静态的,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(temp)-(file)-([w-]+).php$ tempfile-$3.php [R=301,L]

这对我来说是有效的:

 RewriteRule ^(temp-file)(-.+.php)$ /tempfile$2 [L,NC,R=301]

最新更新