Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess-重定向(删除链接中的第一个“-”)_.htaccess_Mod Rewrite - Fatal编程技术网

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

.htaccess-重定向(删除链接中的第一个“-”),.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我现在研究的是一组大链接上的不同重定向规则。例如,如果我想在“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] 但我现在想

我现在研究的是一组大链接上的不同重定向规则。例如,如果我想在“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个rule/cond,例如:

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

如果您有任何建议/解决方案,我将不胜感激。

请尝试以下规则,我假设tempfile是静态的

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]

虽然这段代码可以解决这个问题,但是一个好的答案也应该包含一个解释。(temp文件)1部分将替换为stactic temp文件,(.+\.php)是“-”之后的所有内容,如$2