.htaccess - 重定向(首先删除" - "在链接中)

时间:2017-02-04 06:40:57

标签: .htaccess mod-rewrite

我现在在大量链接上使用一组不同的重定向规则。所以,例如,如果我想添加" - "在" temp"之后例如:

public void addAccount(BackAccount acct) {
    for(int i = 0; i < custAcct.length; i++) {
        if(custAcct[i] == null) {
            custAcct[i] = acct;
            return;
        }
    }
}

我使用以下代码:

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

但我现在要做的就是扭转它,以便首先删除&#34; - &#34;链接中的连字符。我需要1个规则/ cond用于链接集,例如:

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

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

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

这个作品形成了我:

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