【问题标题】:mod_rewrite works incorrectly on apache 2.4mod_rewrite 在 apache 2.4 上无法正常工作
【发布时间】:2015-01-14 06:23:20
【问题描述】:

我之前用过其他主机,一切正常,但现在我已经将其更改为新主机。在新主机上安装了 apache 2.4。

我有以下规则:

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /
        RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
        RewriteRule ^/?(.*) http://%1/$1 [L,R=permanent]

        RewriteRule manage/ajax/(.*?)$ manage/ajax/index.php [QSA,L]
        RewriteRule manage/json/(.*?)$ manage/json/index.php [QSA,L]

        RewriteCond %{REQUEST_URI} !\.(.+)$
        RewriteRule ckfinder/(.*?)$ ckfinder/index.html [QSA,L]

        RewriteCond %{REQUEST_URI} !\.(.+)$
        RewriteRule manage/(.*?)/$ manage/index.php [QSA,L]

        RewriteCond %{REQUEST_URI} !\.(.+)$
        RewriteRule ajax/(.+?) ajax/index.php [QSA,L]

        RewriteCond %{REQUEST_URI} !\.(.+)$
        RewriteRule api/(.*?) /api/index.php [QSA,L]

        RewriteCond %{REQUEST_URI} !\.(.+)$
        RewriteRule (.*) index.php
</IfModule>

当我尝试访问例如 /manage/ 时,它会显示索引页面,但如果我将一些额外的数据添加到路径中,它将显示我需要的内容。例如:/manage/some_data - 可以正常工作。但我想通过 /manage/ 访问正确的目录。

【问题讨论】:

  • 只需在 .htaccess 顶部使用 DirectoryIndex index.php
  • 谢谢,这解决了我的问题。
  • 不客气,很高兴它有帮助。

标签: apache .htaccess mod-rewrite apache2 apache2.4


【解决方案1】:

更改此规则:

RewriteCond %{REQUEST_URI} !\.(.+)$
RwriteRule manage/(.*?)/$ manage/index.php [QSA,L]

RewriteCond %{REQUEST_URI} !\.(.+)$
RwriteRule manage(/.*)?$ manage/index.php [QSA,L]

【讨论】:

  • 同样的结果,没有任何改变。
  • 绝对确定您输入正确?正则表达式应该可以工作。见这里:regex101.com/r/jN1jA8/2
  • 我不认为问题出在正则表达式中,因为我的规则在旧服务器上运行良好。我认为逻辑上存在问题,也许在新的 apache 中使用 mod_rewrite 发生了一些变化?
  • 好吧,您的旧正则表达式看起来不正确,它只会匹配您所看到的,即manage/some_datamanage//(.*?) 部分会阻止manage/一场比赛。
  • 好吧,也许我的正则表达式也错了,但你的正则表达式并没有解决我的问题。此外,如您所见,还有 api、ajax 和其他。我对所有这些查询都有同样的问题。我觉得主逻辑有问题。
猜你喜欢
  • 2015-12-03
  • 2011-08-12
  • 2014-03-02
  • 1970-01-01
  • 2018-09-14
  • 2012-08-05
  • 2016-03-31
  • 2016-12-01
相关资源
最近更新 更多