【问题标题】:Simple Rewrite Rule issue简单的重写规则问题
【发布时间】:2022-01-25 23:29:24
【问题描述】:

我很难理解这条重写规则的第 3 行有什么问题:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
RewriteRule ^fr/lecon-de-kite\.html$ kite-lessons.php?lang=fr [L]
RewriteRule ^fr$ index.php?lang=fr [L]
RewriteRule ^it$ index.php?lang=it [L]

当我尝试访问 http://localhost/kitemeup/fr/lecon-de-kite.html 时,我收到 Not Found 错误

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    在您的站点根目录 .htaccess 中像这样:

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^fr/lecon-de-kite\.html$ kite-lessons.php?lang=fr [L]
    RewriteRule ^(it|fr)/?$ index.php?lang=$1 [L,QSA]
    
    RewriteRule ^(.+)\.html$ $1.php [L,NC]
    

    只需了解规则的顺序很重要,因为 mod_rewrite 从上到下处理它们。您的 html -> php 规则优先并将所有 .html URI 转换为 .php 使您的第二条规则无效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      • 2011-02-23
      相关资源
      最近更新 更多