简体   繁体   English

用绝对URL处理〜600个永久重定向的最佳方法是什么?

[英]What is the best way to handle ~600 permanent redirects with absolute URLs?

I have around 600 old URLs in this format: 我有大约600个旧网址采用以下格式:

http://www.example.com?articlename.random-numbers.html

which I want to redirect to the new format: 我想重定向到新格式:

http://www.example.com?p=XXX (article number)

There is no correlation between the old and new URLs that I can use to create a common rule. 我可以用来创建通用规则的新旧URL之间没有关联。 I just have a list of the URL mapping. 我只列出了URL映射。 The old URLs will not exist any more, if that matters. 如果需要的话,旧的URL将不再存在。

Can I use .htaccess or something else for this, or will I have to create my own solution in PHP? 我可以为此使用.htaccess或其他方式,还是必须在PHP中创建自己的解决方案?

I suggest handling this at the server (Apache) level using an .htaccess file. 我建议使用.htaccess文件在服务器(Apache)级别处理此问题。

Because the old URLs will not exist anymore, you should set these up as HTTP Status Code 301 redirects, as they indicate a permanent move: http://en.wikipedia.org/wiki/HTTP_301 由于旧的URL将不再存在,因此您应将其设置为HTTP状态代码301重定向,因为它们指示了永久的移动: http : //en.wikipedia.org/wiki/HTTP_301

In your .htaccess file, for every article, create a line as follows: 在您的.htaccess文件中,为每篇文章创建一行,如下所示:

Redirect 301 /?articlename.random-numbers.html http://www.yourdomain.com/?p=XXX

Your .htaccess file should sit at the root of your website. 您的.htaccess文件应位于网站的根目录。

Because there is no correlation between the old and new URLs that you can use to create a common rule, having a ~600 line .htaccess file is your best bet. 因为您可以用来创建通用规则的新旧URL之间没有关联,所以最好使用〜600行的.htaccess文件。 (If there was some correlation, you could use Apache's mod_rewrite module to script this task.) (如果存在某种关联,则可以使用Apache的mod_rewrite模块来编写此任务的脚本。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM