包含点的URL的重定向

时间:2016-07-31 01:54:34

标签: apache .htaccess url url-rewriting

我错误地创建了包含点的网址。为了更新点' - '我已更新数据库中的所有URL,同时我已将以下行添加到我的.htaccess

# Don't rewrite any URIs ending with a file extension (ending with .[xxxx])
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{2,5}$

现在有什么方法可以在.htaccess中添加RewriteRule或条件,这样所有包含点的网址都可以通过用&替换点来重定向 - ' ?

1 个答案:

答案 0 :(得分:0)

是的,这非常简单。您使用捕获组在.之前和之后进行匹配,然后使用backrefences创建包含-的新网址。

RewriteCond %{REQUEST_URI} ^/(.+)\.(.+)$ [NC]
RewriteRule ^ /%1-%2 [R=301,L]

让我知道这是怎么解决的。

相关问题