【问题标题】:.htaccess file working, but not rewriting url.htaccess 文件工作,但不重写 url
【发布时间】:2014-02-22 20:54:21
【问题描述】:

是时候隐藏 get 变量了,但是我的 .htaccess 文件不允许重写。我目前有这个:

RewriteEngine On
RewriteRule ^timeline/(\d.*) timeline.php?user=$1

它是timeline.php?user=chris,必须是timeline.php

我找了将近 2 个小时,复制和更改代码,但没有任何效果。

我也变了

<Directory ..>
...
AllowOverride None
...
</Directory>

到:

AllowOverride All

请帮忙!

【问题讨论】:

  • 我认为你不能像这样隐藏 get 变量。最好的情况是你可以做类似timeline.php/user/chris 或类似的事情,你的重写会将“chris”填充到“user”$_GET 变量中。
  • 另外,这不是一个独特的问题:stackoverflow.com/questions/14415685/…
  • @cale_b 我​​说我已经研究了将近一个小时,但是这些代码都没有帮助
  • \d 是数字,例如仅限0-9。 chrisNEVER 匹配,因为这些是字母,例如 a-z,而不是数字。请改用^timeline/(.*),或改用^timeline/([a-z]*)

标签: php apache .htaccess mod-rewrite


【解决方案1】:

使用以下 htaccess 并尝试

RewriteEngine On
RewriteRule ^timeline/([^/]*)$ /timeline.php?user=$1 [L]

【讨论】:

  • 这仍然不会重写url
  • 您确定您的 mod_rewrite 已启用吗?经过测试:(
  • 是的,我先检查了
【解决方案2】:

试试这个:

RewriteRule ^timeline/(.*)$ timeline.php?user=$1

【讨论】:

    【解决方案3】:

    我认为您需要通过将行放在 .htaccess 顶部来关闭 MultiViews 选项:

    Options -MultiViews
    
    • 选项MultiViewsApache's content negotiation module 使用,它在mod_rewrite 之前运行,并使Apache 服务器匹配文件的扩展名。所以/file 可以在 URL 中,但它会服务于/file.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多