我想出了如何使用.htaccess将我的朋友老博客档案重定向到他的新WordPress档案:
RewriteEngine On
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#Redirect to WP archive
RedirectMatch 301 ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3
但是,如果某人尝试使用参数m = 1(http://www.mydomain.com/2010_04_01_archive.html?m=1)访问旧存档,则不会重定向!我们希望忽略所有可能的参数,并将其重定向到上面http://www.mydomain.com/2010/04/01/
试过这个,但它不起作用:
RewriteEngine On
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3 [R]
感谢您的帮助! 阿曼达
答案 0 :(得分:0)
试试这段代码:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive\.html$ /$1/$2/$3? [L,R=301,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
答案 1 :(得分:0)
删除第一个/和$。
RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html /$1/$2/$3 [R=301]