doujiao3346 2009-08-30 15:16
浏览 52
已采纳

htaccess 301重定向多个文件

I'm wondering if multiple entries on htaccess will work for 301 redirects.

The problem I see is that old site files have 'html' extension and are named named differently so a simple global redirect won't work, it has to be one rule per file name.

This sites receives 1000 visits daily so need to be careful not to penalize search engine.

RewriteEngine On
RewriteBase /
RewriteRule ^file1\.html$ http://www.domain.com/file1.php [R=301,NC,L]
RewriteRule ^file2\.html$ http://www.domain.com/file2.php [R=301,NC,L]
RewriteRule ^file3\.html$ http://www.domain.com/file3.php [R=301,NC,L]
RewriteRule ^file4\.html$ http://www.domain.com/file4.php [R=301,NC,L]

A php header rewrite will not work as the old files are html type.

  • 写回答

3条回答 默认 最新

  • doushenxu7294 2009-08-30 15:22
    关注

    I suppose you could use some regex to reduce the number of different RewriteRules you are using, as those are all looking the same way.

    In your case, using only this one might be OK :

    RewriteRule ^(file1|file2|file3|file4)\.html$ http://www.metaboforte.com/$1.php [R=301,NC,L]
    

    This way, you specify exactly what you want to rewrite ; but only have 1 RewriteRule.

    Or, a bit more generic :

    RewriteRule ^file([0-9]*)\.html$ http://www.metaboforte.com/file$1.php [R=301,NC,L]
    

    Which allows you to define that you want to rewrite every fileXYZ.html, with XYZ a number. (As I used '*', no number at all would be taken into account by that rewrite rule ; if you want at least one number, you should use '+')

    You could also do something even more generic -- not sure you want that, but something like this might do :

    RewriteRule ^(.*?)\.html$ http://www.metaboforte.com/$1.php [R=301,NC,L]
    

    Here, you are redirecting everything that end with .html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试