doujugu1722 2012-12-05 18:12
浏览 39
已采纳

.htaccess RewriteRule参数

I have a simple .htaccess file:

RewriteEngine on
RewriteRule ^(.+)-([0-9]+)\.html$ book.php?title=$1&id=$2
RewriteRule ^(.+)\.html$ search.php?search=$1

If a users enter "php-for-dumies-10.html" it going to be served as "book.php?title=php-for-dummies&id=10". That works fine.

If a user enters "phpbook.html" it going to be served as "search.php?search=phpbook". That works fine too.

The problem is if a user enters "directory/php-for-dumies-10.html" (adding a directory in the URL) insted of getting "book.php?title=directory/php-for-dumies&id=10" as expected, i'm getting "search.php?search=book.php/php-for-dumies-10"

Why does the second RewriteRule execute instead of the first one? Is because i'm adding a slash? And more important, where is the "book.php/php-for-dummies-10" parameter is coming from?

Thank you for any help.

  • 写回答

1条回答 默认 最新

  • doulupian8725 2012-12-05 18:16
    关注
    RewriteEngine on
    RewriteRule ^(.+)-([0-9]+)\.html$ book.php?title=$1&id=$2 [L]
    RewriteRule ^(.+)\.html$ search.php?search=$1 [L]
    

    Actually, both rewrites are executing. By adding an [L] flag it prevents subsequent rules from executing. This should force only the first rule to execute if its a match.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题