301重定向.htaccess重定向到错误的页面

时间:2014-08-06 10:28:16

标签: apache .htaccess mod-rewrite redirect

我正在尝试将旧主页上不再存在的旧页 /home/samples.html 重定向到 /

我已将重定向写为:Redirect 301 /home/samples.html /

然而,当我访问旧页面时,我被重定向到/non-slip-mats-anti-slip-placematssamples.html

这可能是由于与其他重定向冲突造成的吗?我写的其他人如下:

  Redirect 301 /front-page /
  Redirect 301 /content/mats /non-slip-mats-anti-slip-placemats
  Redirect 301 /content/netting /non-slip-netting
  Redirect 301 /content/self-adhesive-dycem /non-slip-self-adhesive
  Redirect 301 /content/bottle-openers /bottle-openers
  Redirect 301 /content/jar-openers /jar-openers
  Redirect 301 /content/cello-mats /cello-mats
  Redirect 301 /content/coasters /non-slip-coasters
  Redirect 301 /content/product-care /product-care
  Redirect 301 /content/cup-holder /cup-holder
  Redirect 301 /content/reels /reels
  Redirect 301 /content/floor-mats /floor-mats
  Redirect 301 /content/promotional-items /promotional-items
  Redirect 301 /babies.php /
  Redirect 301 /hippomats.php /non-slip-mats-anti-slip-placemats
  Redirect 301 /reels.php /reels
  Redirect 301 /netting.php /non-slip-netting
  Redirect 301 /jaropener.php /jar-openers
  Redirect 301 /catering.php /catering
  Redirect 301 /bottleopener.php /bottle-openers
  Redirect 301 /mats.php /non-slip-mats-anti-slip-placemats
  Redirect 301 /coasters.php /non-slip-coasters
  Redirect 301 /home.php /
  Redirect 301 /panels.php /non-slip-self-adhesive
  Redirect 301 /floormat.php /floor-mats
  Redirect 301 /music.php /music
  Redirect 301 /content/occupational-therapy /occupational-therapy
  Redirect 301 /pdf/ot.pdf /occupational-therapy
  Redirect 301 /trayliner.php /non-slip-mats-anti-slip-placemats
  Redirect 301 /cupholder.php /cup-holder
  Redirect 301 /rehab.php /occupational-therapy
  Redirect 301 /healthcare/index.php /
  Redirect 301 /customersample.php /
  Redirect 301 /usage.php /
  Redirect 301 /home/reels.php /reels
  Redirect 301 /home/music.php /music
  Redirect 301 /discs.php /non-slip-self-adhesive
  Redirect 301 /furnituredisc.php /non-slip-self-adhesive
  Redirect 301 /promo.php /promotional-items
  Redirect 301 /prodgeneral.html /
  Redirect 301 /vat/VAT.php /
  Redirect 301 /vat/vat.doc /
  Redirect 301 /home/samples.html /
  Redirect 301 /home /non-slip-mats-anti-slip-placemats 

1 个答案:

答案 0 :(得分:1)

这是因为这两条规则中的重定向冲突:

Redirect 301 /home/samples.html /
Redirect 301 /home /non-slip-mats-anti-slip-placemats 

您可以看到/home也匹配/home/samples.html URI。你最好使用RedirectMatch来获得它的正则表达式功能。所以使用这些规则:

RedirectMatch 301 ^/home/samples\.html$ /
RedirectMatch 301 ^/home/?$ /non-slip-mats-anti-slip-placemats 

同样,您可以将所有301规则转换为使用RedirectMatch