开发者

Redirect Large Number of URLs (HTML Files) to Wordpress

I have over 2000 HTML files that are now in Wordpress blog. I have 开发者_运维百科the URL Map of Old_file.html and new wordpress URL.

I want 301 redirect but don't want to add 2000 lines to htaccess. Can you please suggest how to accomplish this using PHP so that when there is a request for old url, the php script should lookup into the database and redirect(301) to the new URL ?

Thanks.


You can make your map a mod_rewrite rewrite map like this:

# old    new
Old_file new-url

Then you just need to register the rewrite map in the server or virtual host configuration:

RewriteMap examplemap txt:/path/to/file/map.txt

And finally set a rule that does the redirect (either in your server/virtual host configuration or an .htaccess file):

RewriteCond %{examplemap:$1} .+
RewriteRule ^/?(.+)\.html$ /blog/%0 [L,R=301]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜