【问题标题】:Combining two RewriteRules is overriding the first结合两个 RewriteRules 覆盖第一个
【发布时间】:2020-09-13 21:31:27
【问题描述】:

我正在尝试同时应用两个 RewriteRules。它们都完全按照预期独立工作(当另一个被注释掉时),但是当放在.htaccess 文件中时,只有第一个规则有效。

如何同时使用这些?

RewriteEngine On

# Redirect everything to this file
RewriteRule ^ public/index.php [QSA,L]

# Rewrite location of the storage files making them public
RewriteRule ^storage/(.*)$ app/files/public/$1 [QSA]

【问题讨论】:

  • 更改订单?您的第一条规则适用于 所有 请求,然后您在其中得到 L 标志,表示“完成这一轮”。所以当然第二条规则永远不会适用。重写的经验法则是 - 始终按照从更具体到不太具体的顺序进行。
  • @CBroe 感谢您的建议,但更改顺序不允许两种规则共存。
  • 您是否将L 标志放在 - 现在 - 第一条规则上,以便第二条不会将 everything 重写到公用文件夹中的 index.php之后再来一次?
  • @CBroe 谢谢你的解释。这很有帮助。

标签: html apache .htaccess mod-rewrite


【解决方案1】:

感谢@CBroe 的帮助,这是解决方案:

RewriteEngine On

# Rewrite location of the storage files making them public
RewriteRule ^storage/(.*)$ app/files/public/$1 [QSA,L]

# Redirect everything to this file
RewriteRule ^ public/index.php [QSA]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-05
    • 2012-03-31
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多