2015-11-10 209 views
1

我如何可以重定向从重定向WordPress的永久链接

example.com/%year%/%monthnum%/%postname%.html

一个WordPress的永久链接

example.com/%postname%

我试图这样做,通过一个插件,并通过添加以下代码来.htaccess文件,但它的返回404未找到错误。

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ http://www.example.com/$3

回答

0

试试这个在您的.htaccess文件:

RewriteRule ^[0-9]{4}/[0-9]{2}/(.*)\.html$ /$1 [R=301,L] 

确保它是WordPress默认重写规则之上。

E.g.

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteRule ^[0-9]{4}/[0-9]{2}/(.*)\.html$ /$1 [R=301,L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 
+1

非常感谢! 它工作完美。 – Satish

+0

很高兴工作。如果这是正确的答案,请点击答案左侧的复选标记图标接受答案。 – drew010

相关问题