我正在移动约38个网站从Joomla转到wordpress。
我想保持相同的链接结构,因为SEO。不幸的是,最后一位开发人员对他们构建链接的方式粗心大意,所以我有一些古怪的要求要完成。
也就是说,有时他们的博客是index.php/ blog -4,同时是index.php/blog和index.php/blog-5。
在wordpress中,我制作了permalinks
index.php/blog-5/%postname%
我以前从未编辑过.htaccess,但是我想要做的是重定向到
/blog/* -> /blog-5/*
/博客-4/*->/博客-5/*
我会写些什么来完成这个任务?
编辑
我在执行Michael的答案时遇到了困难。下面是我的.htaccess的样子。我试过把它放在里面和外面。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} !^/blog-5
RewriteRule ^blog(-.+)?/(.*) blog-5/$2 [L,R=301]
</IfModule>
# END WordPress发布于 2012-12-15 14:22:17
这是一个相当简单的RewriteRule。使用表达式(-4)?可以选择匹配-4,并将其与请求一起重定向到/blog-5到/blog/。在(.*)之后的第二个/组将所有其他内容捕获到$2中。
RewriteEngine On
RewriteRule ^blog(-4)?/(.*) blog-5/$2 [L]以上将进行无声的内部重写。如果您实际上想要重定向并让浏览器显示新的URL,请将[L]更改为[L,R=301]。
注意:实现blog-4可能是一个变量名,使用(-.+)?来匹配任何内容。但是你也需要一个RewriteCond,所以它与blog-5不匹配
RewriteCond %{REQUEST_URI} !^/blog-5
RewriteRule ^blog(-.+)?/(.*) blog-5/$2 [L]https://stackoverflow.com/questions/13892983
复制相似问题