doupeng5320 2012-12-13 20:03
浏览 101
已采纳

htaccess - 将.shtml和.html重写为。 PHP

I'm pretty green with mod_rewrite. I've got the first line of this working like a champ, but the second part refuses to cooperate

RewriteRule ^(.*).html$ $1.php
RewriteRule ^(.*).shtml$ $1.php [R=301,L]

The .shtml part fails wonderfully and 404s - without my custom 404 page. Should this be combined in to one rule? Should I quit my job and let them hire a monkey to replace me? has anyone got a solution for this?

Thanks!

  • 写回答

1条回答 默认 最新

  • dougaicha5258 2012-12-13 20:05
    关注

    Assuming you are intending to redirect both .shtml and .html to .php...

    These should both be combined into one rule, and the problem looks to be that both match because the unescaped . before .html stands for "any character", which therefore also matches shtml.

    The pattern \.s?html will match the literal ., followed by an optional s, and ending with html.

    RewriteEngine On
    RewriteRule ^(.*)\.s?html$ $1.php [R=301,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站