【问题标题】:Moving mod_rewrite from httpd.conf to .htaccess doesn't work将 mod_rewrite 从 httpd.conf 移动到 .htaccess 不起作用
【发布时间】:2012-04-17 03:23:32
【问题描述】:

我认为这可能相对简单。我有一个重写规则,它基本上从 URL 中删除 .php,但它不是标准 URL。它在我的 httpd.conf 文件中运行良好,但如果我移至 .htaccess 则不行:

RewriteEngine On
RewriteRule ^/index/(.*)/(.*)$ /index.php/$1/$2 [QSA]

现在我知道在 .htaccess 中您必须删除引用当前目录的部分,但我还没有运气,欢迎提出任何想法/建议/解决方案。

【问题讨论】:

  • 您是否在虚拟主机目录定义中指定了AllowOverride All
  • 嗨皮埃尔-奥利维尔,是的,我做到了。正在读取的 .htaccess 文件。

标签: apache mod-rewrite


【解决方案1】:

传递给 RewriteRule 的 URL 从来没有初始斜线。去掉它。而替换中的那个,因为they're filesystem paths

Given Rule                                      Resulting Substitution
----------------------------------------------  ----------------------------------
^localpath(.*) otherpath$1                      /somepath/otherpath/pathinfo

【讨论】:

  • 嗨,Ignacio 感谢您的回复,在此期间找到了解决方法,但仍想深入了解。我经历过很多版本,无论有没有斜线。困扰我的事情是删除索引上的 .php,我将 .htaccess 设置为文件名本地,但我仍然需要在该目录中引用自身。
猜你喜欢
  • 2013-07-18
  • 2010-12-04
  • 2017-12-27
  • 2014-08-22
  • 2017-01-16
  • 2020-11-24
  • 2013-09-21
  • 2017-04-05
  • 2011-07-04
相关资源
最近更新 更多