使用正则表达式替换/重定向.htaccess

时间:2013-12-09 17:55:39

标签: regex wordpress apache .htaccess mod-rewrite

我已将我的网站从joomla转移到wordpress。大多数旧链接都被重定向得很好,但我得到了一些奇怪的404s

我想要的是能够重定向这个:

http://www.pcsteps.gr/component/content/article?id=575:how-to-guide-wireless-network-security

对此:http://www.pcsteps.gr/575-how-to-guide-wireless-network-security

这是我在.htaccess文件中使用的代码:

RewriteRule ^component/content/(.+)$ pcsteps.gr/$1 [R=301,L]

此代码删除了网址的/ component / content /部分,但我留下了“文章?id = 575:how-to-guide-wireless-network-security”

如何更改代码以删除“article?id =”,保留数字并将“:”替换为“ - ”?

1 个答案:

答案 0 :(得分:1)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)id=([0-9]+):([^&]+)
RewriteRule ^component/content/article/?$ /%1-%2? [L,NC,R=301]