douba1214 2013-03-29 23:23
浏览 42

mod_rewrite影响get变量

I have a PHP based blog on Apache with a simple mod_rewrite happening:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(.*)$ index.php?story=$1 [L]

However, when I look at $_GET['story'] in the PHP script, it gives me "index.php" everytime.

Any ideas?

  • 写回答

1条回答 默认 最新

  • doudie2693 2013-03-29 23:33
    关注

    Apache will run the rules again if there are any changes made during a pass that cause either an internal or external redirect. You should catch this with a rule for index.php

    RewriteRule ^index\.php$ - [L]
    

    that just uses that address as is. This is what WordPress does.

    Depending on your version of apache you can set the rewrite log level to 8 either with RewriteLogLevel or LogLevel. On older versions this must be done in the httpd.conf, so you need a local test site.

    Don't leave that logging on or your performance will suffer.

    Edit:

    Here's a quote from the docs on the rerun under the L flag:

    If you are using RewriteRule in either .htaccess files or in sections, it is important to have some understanding of how the rules are processed. The simplified form of this is that once the rules have been processed, the rewritten request is handed back to the URL parsing engine to do what it may with it. It is possible that as the rewritten request is handled, the .htaccess file or section may be encountered again, and thus the ruleset may be run again from the start. Most commonly this will happen if one of the rules causes a redirect - either internal or external - causing the request process to start over.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)